function InlineBlockEntityOperations::removeUnusedForEntityOnSave
Same name in other branches
- 9 core/modules/layout_builder/src/InlineBlockEntityOperations.php \Drupal\layout_builder\InlineBlockEntityOperations::removeUnusedForEntityOnSave()
- 8.9.x core/modules/layout_builder/src/InlineBlockEntityOperations.php \Drupal\layout_builder\InlineBlockEntityOperations::removeUnusedForEntityOnSave()
- 11.x core/modules/layout_builder/src/InlineBlockEntityOperations.php \Drupal\layout_builder\InlineBlockEntityOperations::removeUnusedForEntityOnSave()
Remove all unused inline blocks on save.
Entities that were used in prevision revisions will be removed if not saving a new revision.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The parent entity.
1 call to InlineBlockEntityOperations::removeUnusedForEntityOnSave()
- InlineBlockEntityOperations::handlePreSave in core/
modules/ layout_builder/ src/ InlineBlockEntityOperations.php - Handles saving a parent entity.
File
-
core/
modules/ layout_builder/ src/ InlineBlockEntityOperations.php, line 81
Class
- InlineBlockEntityOperations
- Defines a class for reacting to entity events related to Inline Blocks.
Namespace
Drupal\layout_builderCode
protected function removeUnusedForEntityOnSave(EntityInterface $entity) {
// If the entity is new or '$entity->original' is not set then there will
// not be any unused inline blocks to remove.
// If this is a revisionable entity then do not remove inline blocks. They
// could be referenced in previous revisions even if this is not a new
// revision.
if ($entity->isNew() || !isset($entity->original) || $entity instanceof RevisionableInterface) {
return;
}
// If the original entity used the default storage then we cannot remove
// unused inline blocks because they will still be referenced in the
// defaults.
if ($this->originalEntityUsesDefaultStorage($entity)) {
return;
}
// Delete and remove the usage for inline blocks that were removed.
if ($removed_block_ids = $this->getRemovedBlockIds($entity)) {
$this->deleteBlocksAndUsage($removed_block_ids);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.