public function FixedBlockContent::exportDefaultContent in Fixed Block Content 8
Export the default content stored in config to the content block.
Parameters
bool $update_existing: (optional) Export the contents into the existing block content, if any.
The existing block content entity is deleted and replaced by a new one unless $update_existing is given. If there is no default content defined in the fixed block or it is not valid, a new empty block is created.
Overrides FixedBlockContentInterface::exportDefaultContent
1 call to FixedBlockContent::exportDefaultContent()
- FixedBlockContent::getBlockContent in src/
Entity/ FixedBlockContent.php - Returns the block content entity linked to this fixed block.
File
- src/
Entity/ FixedBlockContent.php, line 179
Class
- FixedBlockContent
- Configuration entity for the fixed block content.
Namespace
Drupal\fixed_block_content\EntityCode
public function exportDefaultContent($update_existing = FALSE) {
$new_block_content = $this
->getDefaultContentHandler()
->exportDefaultContent($this) ?: $this
->newBlockContent();
if ($current_block = $this
->getMappingHandler()
->getBlockContent($this
->id())) {
if ($update_existing) {
// Copy entity identifiers from the existing block into the new one.
$new_block_content
->set('id', $current_block
->id());
$new_block_content
->set('uuid', $current_block
->uuid());
// Set the new block as not new entity.
$new_block_content
->enforceIsNew(FALSE);
// Do not create new revision.
$new_block_content
->setNewRevision(FALSE);
// Save the block, will update the existing.
$new_block_content
->save();
}
else {
// Delete the current block content.
$current_block
->delete();
}
}
$this
->setBlockContent($new_block_content);
}