You are here

protected function SetInlineBlockDependency::getInlineBlockDependency in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php \Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency::getInlineBlockDependency()

Get the access dependency of an inline block.

If the block is used in an entity that entity will be returned as the dependency.

For revisionable entities the entity will only be returned if it is used in the latest revision of the entity. For inline blocks that are not used in the latest revision but are used in a previous revision the entity will not be returned because calling \Drupal\Core\Access\AccessibleInterface::access() will only check access on the latest revision. Therefore if the previous revision of the entity was returned as the dependency access would be granted to inline block regardless of whether the user has access to the revision in which the inline block was used.

Parameters

\Drupal\block_content\BlockContentInterface $block_content: The block content entity.

Return value

\Drupal\Core\Entity\EntityInterface|null Returns the layout dependency.

See also

\Drupal\block_content\BlockContentAccessControlHandler::checkAccess()

\Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()

1 call to SetInlineBlockDependency::getInlineBlockDependency()
SetInlineBlockDependency::onGetDependency in core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php
Handles the BlockContentEvents::INLINE_BLOCK_GET_DEPENDENCY event.

File

core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php, line 125

Class

SetInlineBlockDependency
An event subscriber that returns an access dependency for inline blocks.

Namespace

Drupal\layout_builder\EventSubscriber

Code

protected function getInlineBlockDependency(BlockContentInterface $block_content) {
  $layout_entity_info = $this->usage
    ->getUsage($block_content
    ->id());
  if (empty($layout_entity_info)) {

    // If the block does not have usage information then we cannot set a
    // dependency. It may be used by another module besides layout builder.
    return NULL;
  }
  $layout_entity_storage = $this->entityTypeManager
    ->getStorage($layout_entity_info->layout_entity_type);
  $layout_entity = $layout_entity_storage
    ->load($layout_entity_info->layout_entity_id);
  if ($this
    ->isLayoutCompatibleEntity($layout_entity)) {
    if ($this
      ->isBlockRevisionUsedInEntity($layout_entity, $block_content)) {
      return $layout_entity;
    }
  }
  return NULL;
}