为什么我的自定义代码在日志中显示警告?

时间:2019-04-26 20:11:18

标签: php twitter-bootstrap drupal modal-dialog drupal-8

我在Drupal 8.6和Bootstrap 3.3.7上有一个站点

我创建了一个自定义模块,供客户在下订单时接受商店的条款和条件。

这会显示一个指向付款前复选框的链接,以在模式窗口中显示条款和条件。

在这里下订单时,日志中会显示警告(很抱歉,我的代码太长了,无法在此处发布):

https://pastebin.com/1p5m1Ved

https://pastebin.com/XYbqDJje

https://pastebin.com/P93bStKh

这是造成问题的文件:

<?php

namespace Drupal\commerce_marketplace_terms_and_conditions\Plugin\Commerce\CheckoutPane;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;

/**
 * Provides the completion message pane.
 *
 * @CommerceCheckoutPane(
 *   id = "marketplace_terms_and_conditions",
 *   label = @Translation("Marketplace Terms and Conditions"),
 *   default_step = "review",
 * )
 */
class MarketplaceTermsAndConditions extends CheckoutPaneBase implements CheckoutPaneInterface {

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $store_name = $this->order->getStore()->getName();
    $store_id = $this->order->getStoreId();
    $pane_form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $attributes = [
      'attributes' => [
        'class' => 'use-ajax',
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'width' => auto
        ]),
      ],
    ];
    $link = Link::fromTextAndUrl(
      $this->t('terms and conditions of the store "@store_name"', ['@store_name' => $store_name]),
      Url::fromUri("internal:/store/$store_id/cgv", $attributes)
    )->toString();
    $pane_form['marketplace_terms_and_conditions'] = [
      '#type' => 'checkbox',
      '#default_value' => FALSE,
      '#title' => $this->t('I have read and accept @terms.', ['@terms' => $link]),
      '#required' => TRUE,
      '#weight' => $this->getWeight(),
    ];
    return $pane_form;
  }

}

我的自定义模块出了什么问题以及如何解决该问题?谢谢

1 个答案:

答案 0 :(得分:3)

将此更改为

'width' => auto

'width' => 'auto'

假设它是一个常量,从错误中可以看出,它必须是变量或字符串。