function InlineBlockEntityOperations::handlePreSave

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

Handles saving a parent entity.

Parameters

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

File

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

Class

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

Namespace

Drupal\layout_builder

Code

public function handlePreSave(EntityInterface $entity) {
    if (!$this->isLayoutCompatibleEntity($entity)) {
        return;
    }
    $duplicate_blocks = FALSE;
    if ($sections = $this->getEntitySections($entity)) {
        if ($this->originalEntityUsesDefaultStorage($entity)) {
            // This is a new override from a default and the blocks need to be
            // duplicated.
            $duplicate_blocks = TRUE;
        }
        $new_revision = FALSE;
        if ($entity instanceof RevisionableInterface) {
            // If the parent entity will have a new revision create a new revision
            // of the block.
            // @todo Currently revisions are never created for the parent entity.
            //   This will be fixed in https://www.drupal.org/node/2937199.
            //   To work around this always make a revision when the parent entity
            //   is an instance of RevisionableInterface. After the issue is fixed
            //   only create a new revision if '$entity->isNewRevision()'.
            $new_revision = TRUE;
        }
        foreach ($this->getInlineBlockComponents($sections) as $component) {
            $this->saveInlineBlockComponent($entity, $component, $new_revision, $duplicate_blocks);
        }
    }
    $this->removeUnusedForEntityOnSave($entity);
}

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