From bebf40bd299b969ba2c439bc0fb219ea49a07a46 Mon Sep 17 00:00:00 2001 From: GoZ Date: Sat, 17 Aug 2019 11:57:12 +0200 Subject: [PATCH] Issue #3049332: PHP message: Error: Call to a member function getEntityTypeId() on null (Layout Builder) --- .../src/Plugin/Block/InlineBlock.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/core/modules/layout_builder/src/Plugin/Block/InlineBlock.php b/core/modules/layout_builder/src/Plugin/Block/InlineBlock.php index 01f64eb37f..deaffcee4d 100644 --- a/core/modules/layout_builder/src/Plugin/Block/InlineBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/InlineBlock.php @@ -14,6 +14,7 @@ use Drupal\Core\Form\SubformStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -61,6 +62,13 @@ class InlineBlock extends BlockBase implements ContainerFactoryPluginInterface, */ protected $isNew = TRUE; + /** + * The logger channel. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * The current user. * @@ -81,10 +89,12 @@ class InlineBlock extends BlockBase implements ContainerFactoryPluginInterface, * The entity type manager service. * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository * The entity display repository. + * @param \Psr\Log\LoggerInterface $logger + * The logger channel. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, AccountInterface $current_user = NULL) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, LoggerInterface $logger, AccountInterface $current_user = NULL) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; @@ -93,6 +103,8 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->isNew = FALSE; } + $this->logger = $logger; + if (!$current_user) { @trigger_error('The current_user service must be passed to InlineBlock::__construct(), it is required before Drupal 9.0.0.', E_USER_DEPRECATED); $current_user = \Drupal::currentUser(); @@ -110,6 +122,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('entity_type.manager'), $container->get('entity_display.repository'), + $container->get('logger.channel.layout_builder'), $container->get('current_user') ); } @@ -220,6 +233,9 @@ protected function blockAccess(AccountInterface $account) { */ public function build() { $block = $this->getEntity(); + if (!$block) { + return []; + } return $this->entityTypeManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']); } @@ -236,6 +252,9 @@ protected function getEntity() { } elseif (!empty($this->configuration['block_revision_id'])) { $entity = $this->entityTypeManager->getStorage('block_content')->loadRevision($this->configuration['block_revision_id']); + if (!$entity) { + $this->logger->error('Unable to load inline block content entity with revision ID %vid.', ['%vid' => $this->configuration['block_revision_id']]); + } $this->blockContent = $entity; } else { -- 2.20.1