class InlineBlockEntityOperations implements ContainerInjectionInterface (View source)

internal  This is an internal utility class wrapping hook implementations.
 

Defines a class for reacting to entity events related to Inline Blocks.

Traits

Methods to help with entities using the layout builder.

Properties

protected SectionStorageManagerInterface $sectionStorageManager

The section storage manager.

from  LayoutEntityHelperTrait
protected InlineBlockUsageInterface $usage

Inline block usage tracking service.

protected EntityStorageInterface $blockContentStorage

The block content storage.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

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 $entityTypeManager, InlineBlockUsageInterface $usage, SectionStorageManagerInterface $section_storage_manager)

Constructs a new EntityOperations object.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

removeUnusedForEntityOnSave(EntityInterface $entity)

Remove all unused inline blocks on save.

int[]
getRemovedBlockIds(EntityInterface $entity)

Gets the IDs of the inline blocks that were removed.

handleEntityDelete(EntityInterface $entity)

Handles entity tracking on deleting a parent entity.

handlePreSave(EntityInterface $entity)

Handles saving a parent entity.

int
getPluginBlockId(InlineBlock $block_plugin)

Gets a block ID for an inline block plugin.

deleteBlocksAndUsage(array $block_content_ids)

Delete the inline blocks and the usage records.

removeUnused(int $limit = 100)

Removes unused inline blocks.

int[]
getBlockIdsForRevisionIds(array $revision_ids)

Gets blocks IDs for an array of revision IDs.

saveInlineBlockComponent(EntityInterface $entity, SectionComponent $component, bool $new_revision, bool $duplicate_blocks)

Saves an inline block component.

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 $entityTypeManager, InlineBlockUsageInterface $usage, SectionStorageManagerInterface $section_storage_manager)

Constructs a new EntityOperations object.

This constructor has one optional parameter, $section_storage_manager and one totally unused $database parameter. Deprecate the current constructor signature in https://www.drupal.org/node/3031492 after the general policy for constructor backwards compatibility is determined in https://www.drupal.org/node/3030640.

Parameters

EntityTypeManagerInterface $entityTypeManager

The entity type manager service.

InlineBlockUsageInterface $usage

Inline block usage tracking service.

SectionStorageManagerInterface $section_storage_manager

(optional) The section storage manager.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

protected removeUnusedForEntityOnSave(EntityInterface $entity)

Remove all unused inline blocks on save.

Entities that were used in prevision revisions will be removed if not saving a new revision.

Parameters

EntityInterface $entity

The parent entity.

protected int[] getRemovedBlockIds(EntityInterface $entity)

Gets the IDs of the inline blocks that were removed.

Parameters

EntityInterface $entity

The layout entity.

Return Value

int[]

The block content IDs that were removed.

handleEntityDelete(EntityInterface $entity)

Handles entity tracking on deleting a parent entity.

Parameters

EntityInterface $entity

The parent entity.

handlePreSave(EntityInterface $entity)

Handles saving a parent entity.

Parameters

EntityInterface $entity

The parent entity.

protected int getPluginBlockId(InlineBlock $block_plugin)

Gets a block ID for an inline block plugin.

Parameters

InlineBlock $block_plugin

The inline block plugin.

Return Value

int

The block content ID or null none available.

protected deleteBlocksAndUsage(array $block_content_ids)

Delete the inline blocks and the usage records.

Parameters

array $block_content_ids

The block content entity IDs.

removeUnused(int $limit = 100)

Removes unused inline blocks.

Parameters

int $limit

The maximum number of inline blocks to remove.

protected int[] getBlockIdsForRevisionIds(array $revision_ids)

Gets blocks IDs for an array of revision IDs.

Parameters

array $revision_ids

The revision IDs.

Return Value

int[]

The block IDs.

protected saveInlineBlockComponent(EntityInterface $entity, SectionComponent $component, bool $new_revision, bool $duplicate_blocks)

Saves an inline block component.

Parameters

EntityInterface $entity

The entity with the layout.

SectionComponent $component

The section component with an inline block.

bool $new_revision

Whether a new revision of the block should be created when modified.

bool $duplicate_blocks

Whether the blocks should be duplicated.