我为Drupal 8.6和Drupal Commerce 2创建了一个自定义模块。
它可以工作,但是当我查看drupal日志时,每次重新加载页面时都会收到PHP警告。
我该如何纠正这些警告?
commerce_marketplace_premium_merchant.module :
<?php
/**
* @file
* Hook implementations of commerce_marketplace_premium_merchant module.
*/
use Drupal\commerce_store\Entity\StoreType;
use Drupal\commerce_product\Entity\ProductType;
use Drupal\commerce_product\Entity\ProductVariationType;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_product\Entity\ProductVariation;
function commerce_marketplace_premium_merchant_form_commerce_order_item_add_to_cart_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$current_store = \Drupal::service('commerce_store.current_store');
$owner = $current_store->getStore()->getOwner();
foreach ($form_state->getFormObject()->getEntity()->getPurchasedEntity()->getProduct()->getStores() as $store) {
$bundle = $store->bundle();
// Product type abonnement.
if ($bundle == 'online') {
if (isset($form["#attributes"]["class"]) && in_array("commerce-order-item-add-to-cart-form", $form["#attributes"]["class"])) {
$selectedVariationId = $form_state->get('selected_variation');
$selectedVariation = ProductVariation::load($selectedVariationId);
$form['actions']['submit']['#value'] = t('Subscribe');
if (!$owner->hasRole('marchand')) {
$form['actions']['submit']['#attributes']['class'] = array('button--add-to-cart', 'button button--primary', 'js-form-submit', 'form-submit', 'is-disabled', 'btn-warning', 'btn');
$form['actions']['submit']['#disabled'] = TRUE;
}
}
}
紫衣仙女