class SetInlineBlockDependency implements EventSubscriberInterface (View source)

internal  Tagged services are internal.
 

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

When used within the layout builder the access dependency for inline blocks will be explicitly set but if access is evaluated outside of the layout builder then the dependency may not have been set.

A known example of when the access dependency will not have been set is when determining 'view' or 'download' access to a file entity that is attached to a content block via a field that is using the private file system. The file access handler will evaluate access on the content block without setting the dependency.

Traits

Methods to help with entities using the layout builder.

Properties

protected SectionStorageManagerInterface $sectionStorageManager

The section storage manager.

from  LayoutEntityHelperTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected Connection $database

The database connection.

protected InlineBlockUsageInterface $usage

The inline block usage service.

Methods

bool
isLayoutCompatibleEntity(EntityInterface $entity)

Determines if an entity can have a layout.

int[]
getInlineBlockRevisionIdsInSections(array $sections)

Gets revision IDs for layout sections.

getEntitySections(EntityInterface $entity)

Gets the sections for an entity if any.

getInlineBlockComponents(array $sections)

Gets components that have Inline Block plugins.

getSectionStorageForEntity(EntityInterface $entity)

Gets the section storage for an entity.

bool
originalEntityUsesDefaultStorage(EntityInterface $entity)

Determines if the original entity used the default section storage.

__construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, InlineBlockUsageInterface $usage, SectionStorageManagerInterface $section_storage_manager)

Constructs SetInlineBlockDependency object.

static 
getSubscribedEvents()

{@inheritdoc}

onGetDependency(BlockContentGetDependencyEvent $event)

Handles the BlockContentEvents::INLINE_BLOCK_GET_DEPENDENCY event.

getInlineBlockDependency(BlockContentInterface $block_content)

Get the access dependency of an inline block.

bool
isBlockRevisionUsedInEntity(EntityInterface $layout_entity, BlockContentInterface $block_content)

Determines if a block content revision is used in an entity.

Details

protected bool isLayoutCompatibleEntity(EntityInterface $entity)

Determines if an entity can have a layout.

Parameters

EntityInterface $entity

The entity to check.

Return Value

bool

TRUE if the entity can have a layout otherwise FALSE.

protected int[] getInlineBlockRevisionIdsInSections(array $sections)

Gets revision IDs for layout sections.

Parameters

array $sections

The layout sections.

Return Value

int[]

The revision IDs.

protected Section[] getEntitySections(EntityInterface $entity)

Gets the sections for an entity if any.

Parameters

EntityInterface $entity

The entity.

Return Value

Section[]

The entity layout sections if available.

protected SectionComponent[] getInlineBlockComponents(array $sections)

Gets components that have Inline Block plugins.

Parameters

array $sections

The layout sections.

Return Value

SectionComponent[]

The components that contain Inline Block plugins.

protected SectionStorageInterface|null getSectionStorageForEntity(EntityInterface $entity)

Gets the section storage for an entity.

Parameters

EntityInterface $entity

The entity.

Return Value

SectionStorageInterface|null

The section storage if found otherwise NULL.

protected bool originalEntityUsesDefaultStorage(EntityInterface $entity)

Determines if the original entity used the default section storage.

This method can be used during the entity save process to determine whether $entity->original is set and used the default section storage plugin as determined by ::getSectionStorageForEntity().

Parameters

EntityInterface $entity

The entity.

Return Value

bool

TRUE if the original entity used the default storage.

__construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, InlineBlockUsageInterface $usage, SectionStorageManagerInterface $section_storage_manager)

Constructs SetInlineBlockDependency object.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

Connection $database

The database connection.

InlineBlockUsageInterface $usage

The inline block usage service.

SectionStorageManagerInterface $section_storage_manager

The section storage manager.

static getSubscribedEvents()

{@inheritdoc}

onGetDependency(BlockContentGetDependencyEvent $event)

Handles the BlockContentEvents::INLINE_BLOCK_GET_DEPENDENCY event.

Parameters

BlockContentGetDependencyEvent $event

The event.

protected EntityInterface|null getInlineBlockDependency(BlockContentInterface $block_content)

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

BlockContentInterface $block_content

The block content entity.

Return Value

EntityInterface|null

Returns the layout dependency.

See also

BlockContentAccessControlHandler::checkAccess
BlockComponentRenderArray::onBuildRender

protected bool isBlockRevisionUsedInEntity(EntityInterface $layout_entity, BlockContentInterface $block_content)

Determines if a block content revision is used in an entity.

Parameters

EntityInterface $layout_entity

The layout entity.

BlockContentInterface $block_content

The block content revision.

Return Value

bool

TRUE if the block content revision is used as an inline block in the layout entity.