【问题标题】:Why does my custom code show warnings in the logs?为什么我的自定义代码在日志中显示警告?
【发布时间】:2019-09-16 08:48:15
【问题描述】:

我在 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;
  }

}

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

【问题讨论】:

  • 常量auto 应该是什么?

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


【解决方案1】:

把这个改成

'width' => auto

这个

'width' => 'auto'

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

【讨论】:

  • 谢谢,这已经解决了 2 个警告,但我仍然有这个 pastebin.com/XYbqDJje
  • 我能看到你得到这个错误的页面的代码吗,如果我没有错,可能是因为你试图回显一个数组,而不是你必须通过aray 变量及其键。
  • 会比较复杂,因为是购买隧道的页面。你要看什么 ?源代码?
  • 我不熟悉drupal,但是由于数组被回显,可能会抛出错误“数组到字符串转换”。例如&lt;?php $ace = [ 0 =&gt; 'acd', 1 =&gt; 'asd' ]; echo $ace; //Array to string conversion error echo $ace[0].' '.$ace[1]; //no error ?&gt;
  • 如果您使用 print_r() 代替 echo,您可能能够找出导致此问题的问题,echo 只能打印字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-08
  • 1970-01-01
相关资源
最近更新 更多