function InlineBlock::saveBlockContent

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

Saves the block_content entity for this plugin.

Parameters

bool $new_revision: Whether to create new revision.

bool $duplicate_block: Whether to duplicate the "block_content" entity.

File

core/modules/layout_builder/src/Plugin/Block/InlineBlock.php, line 275

Class

InlineBlock
Defines an inline block plugin type.

Namespace

Drupal\layout_builder\Plugin\Block

Code

public function saveBlockContent($new_revision = FALSE, $duplicate_block = FALSE) {
    
    /** @var \Drupal\block_content\BlockContentInterface $block */
    $block = NULL;
    if (!empty($this->configuration['block_serialized'])) {
        $block = unserialize($this->configuration['block_serialized']);
    }
    if ($duplicate_block) {
        if (empty($block) && !empty($this->configuration['block_revision_id'])) {
            $block = $this->entityTypeManager
                ->getStorage('block_content')
                ->loadRevision($this->configuration['block_revision_id']);
        }
        if ($block) {
            $block = $block->createDuplicate();
        }
    }
    if ($block) {
        if ($new_revision) {
            $block->setNewRevision();
        }
        $block->save();
        $this->configuration['block_revision_id'] = $block->getRevisionId();
        $this->configuration['block_serialized'] = NULL;
    }
}

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