function InlineBlockEntityOperations::getRemovedBlockIds

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/InlineBlockEntityOperations.php \Drupal\layout_builder\InlineBlockEntityOperations::getRemovedBlockIds()
  2. 8.9.x core/modules/layout_builder/src/InlineBlockEntityOperations.php \Drupal\layout_builder\InlineBlockEntityOperations::getRemovedBlockIds()
  3. 10 core/modules/layout_builder/src/InlineBlockEntityOperations.php \Drupal\layout_builder\InlineBlockEntityOperations::getRemovedBlockIds()

Gets the IDs of the inline blocks that were removed.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The layout entity.

Return value

int[] The block content IDs that were removed.

1 call to InlineBlockEntityOperations::getRemovedBlockIds()
InlineBlockEntityOperations::removeUnusedForEntityOnSave in core/modules/layout_builder/src/InlineBlockEntityOperations.php
Remove all unused inline blocks on save.

File

core/modules/layout_builder/src/InlineBlockEntityOperations.php, line 112

Class

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

Namespace

Drupal\layout_builder

Code

protected function getRemovedBlockIds(EntityInterface $entity) {
    $original_sections = $this->getEntitySections($entity->original);
    $current_sections = $this->getEntitySections($entity);
    // Avoid un-needed conversion from revision IDs to block content IDs by
    // first determining if there are any revisions in the original that are not
    // also in the current sections.
    $current_block_content_revision_ids = $this->getInlineBlockRevisionIdsInSections($current_sections);
    $original_block_content_revision_ids = $this->getInlineBlockRevisionIdsInSections($original_sections);
    if ($unused_original_revision_ids = array_diff($original_block_content_revision_ids, $current_block_content_revision_ids)) {
        // If there are any revisions in the original that aren't in the current
        // there may some blocks that need to be removed.
        $current_block_content_ids = $this->getBlockIdsForRevisionIds($current_block_content_revision_ids);
        $unused_original_block_content_ids = $this->getBlockIdsForRevisionIds($unused_original_revision_ids);
        return array_diff($unused_original_block_content_ids, $current_block_content_ids);
    }
    return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.