dourun2990 2018-12-17 23:15 采纳率: 100%
浏览 32

我发布产品字段和消息堆栈模块有一个PHP错误

I have a site with Drupal 8, Drupal Commerce 2.11 and the Message module.

I created a message template to create a message when a product is published :

<?php

/**
 * @file
 * Holds hook implementation for the Message Activity Stream module.
 */

use Drupal\Core\Entity\ContentEntityBase;
use Drupal\group\Entity\Group;
use Drupal
ode\Entity\Node;
use Drupal\comment\Entity\Comment;
use Drupal\commerce_store\Entity\Store;
use Drupal\commerce_product\Entity\Product;
use Drupal\user\Entity\User;
use Drupal\profile\Entity\Profile;
use Drupal\message\Entity\Message;

/**
 * Implements hook_commerce_product_insert().
 */
function message_activity_stream_commerce_product_insert(Product $commerce_product) {
  $message = Message::create(['template' => 'mas_create_product', 'uid' => $commerce_product->get('uid')]);
  $message->set('field_product_reference', $commerce_product);
  $message->set('field_published', $commerce_product->isPublished());
  $message->save();
}

/**
 * Implements hook_node_insert().
 */
function message_activity_stream_node_insert(Node $node) {
  $message = Message::create(['template' => 'mas_create_node', 'uid' => $node->get('uid')]);
  $message->set('field_node_reference', $node);
  $message->set('field_published', $node->isPublished());
  $message->save();
}

/**
 * Implements hook_commerce_product_update().
 */
function message_activity_stream_commerce_product_update(Product $commerce_product) {
  if (empty($commerce_product->original)) {
    return;
  }

  message_activity_stream_update_message_status($commerce_product);
}

/**
 * Implements hook_node_update().
 */
function message_activity_stream_node_update(Node $node) {
  if (empty($node->original)) {
    return;
  }

  message_activity_stream_update_message_status($node);
}

/**
 * Set message entity published field when it changes in the related entity.
 *
 * @param \Drupal\Core\Entity\ContentEntityBase $entity
 *   The entity object.
 */
function message_activity_stream_update_message_status(ContentEntityBase $entity) {
  if ($entity->isPublished() == $entity->original->isPublished()) {
    return;
  }

  $query = \Drupal::entityQuery('message');

  $field = 'field_' . $entity->getEntityType()->id() . '_reference';
  $query->condition($field . '.target_id', $entity->id());

  $results = $query->execute();

  if (empty($results)) {
    return;
  }

  $messages = Message::loadMultiple($results);

  foreach ($messages as $message) {
    $message->set('field_published', $entity->isPublished());
    $message->save();
  }
}

If I register my product by publishing it and modify it by unpublishing it, an error is displayed :

The website encountered an unexpected error. Please try again later.

Error: Call to a member function getColumns() on boolean in Drupal\Core\Entity\Query\Sql\Tables->addField() (line 236 of /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php) #0 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php(52): Drupal\Core\Entity\Query\Sql\Tables->addField('field_commerce_...', 'INNER', NULL) #1 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(162): Drupal\Core\Entity\Query\Sql\Condition->compile(Object(Drupal\Core\Database\Driver\mysql\Select)) #2 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(73): Drupal\Core\Entity\Query\Sql\Query->compile() #3 /var/www/www-domaine-com/web/modules/custom/message_activity_stream/message_activity_stream.module(122): Drupal\Core\Entity\Query\Sql\Query->execute() #4 /var/www/www-domaine-com/web/modules/custom/message_activity_stream/message_activity_stream.module(81): message_activity_stream_update_message_status(Object(Drupal\commerce_product\Entity\Product)) #5 [internal function]: message_activity_stream_commerce_product_update(Object(Drupal\commerce_product\Entity\Product)) #6 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('message_activit...', Array) #7 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(204): Drupal\Core\Extension\ModuleHandler->invokeAll('commerce_produc...', Array) #8 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(756): Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object(Drupal\commerce_product\Entity\Product)) #9 /var/www/www-domaine-com/web/modules/contrib/commerce/src/CommerceContentEntityStorage.php(92): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object(Drupal\commerce_product\Entity\Product)) #10 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(507): Drupal\commerce\CommerceContentEntityStorage->invokeHook('update', Object(Drupal\commerce_product\Entity\Product)) #11 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(641): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\commerce_product\Entity\Product), true) #12 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(432): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\commerce_product\Entity\Product), true) #13 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(774): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\commerce_product\Entity\Product)) #14 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Entity/Entity.php(390): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\commerce_product\Entity\Product)) #15 /var/www/www-domaine-com/web/modules/contrib/commerce/modules/product/src/Form/ProductForm.php(233): Drupal\Core\Entity\Entity->save() #16 [internal function]: Drupal\commerce_product\Form\ProductForm->save(Array, Object(Drupal\Core\Form\FormState)) #17 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #18 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #19 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #20 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Form/FormBuilder.php(318): Drupal\Core\Form\FormBuilder->processForm('commerce_produc...', Array, Object(Drupal\Core\Form\FormState)) #21 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('commerce_produc...', Object(Drupal\Core\Form\FormState)) #22 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #23 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #24 /var/www/www-domaine-com/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #25 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #26 /var/www/www-domaine-com/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #27 /var/www/www-domaine-com/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #28 /var/www/www-domaine-com/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #29 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /var/www/www-domaine-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /var/www/www-domaine-com/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #33 /var/www/www-domaine-com/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #34 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #35 /var/www/www-domaine-com/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #36 /var/www/www-domaine-com/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #37 /var/www/www-domaine-com/web/core/lib/Drupal/Core/DrupalKernel.php(669): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #38 /var/www/www-domaine-com/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #39 {main}.

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用