layout_builder_browser.install in Layout Builder Browser 8
File
layout_builder_browser.installView source
<?php
/**
* Migrate layout builder blocks to be config entities on their own.
*/
function layout_builder_browser_update_8001() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory
->listAll('layout_builder_browser.layout_builder_browser_blockcat.') as $blockcat_configname) {
$blockcat = $config_factory
->getEditable($blockcat_configname);
$category_id = $blockcat
->get('id');
$config_blocks = $blockcat
->get('blocks');
if ($config_blocks) {
foreach ($config_blocks as $config_block) {
$lBBlockStorage = \Drupal::entityTypeManager()
->getStorage('layout_builder_browser_block');
$blockdefinition = \Drupal::service('plugin.manager.block')
->getDefinition($config_block['block_id']);
$lBlock = $lBBlockStorage
->create([
'id' => str_replace(':', '', $config_block['block_id']),
'block_id' => $config_block['block_id'],
'category' => $category_id,
'label' => (string) $blockdefinition['admin_label'],
'weight' => $config_block['weight'] ?: 0,
'image_path' => $config_block['image_path'] ?: '',
'image_alt' => $config_block['image_alt'] ?: '',
]);
$lBlock
->save();
}
$blockcat
->clear('blocks')
->save();
}
}
}
/**
* #3184784: Ensure block config entity is installed on existing sites.
*/
function layout_builder_browser_update_8002() {
/** @var \Drupal\Core\Entity\EntityTypeManager $entity_manager */
$entity_manager = \Drupal::service('entity_type.manager');
$entity_manager
->clearCachedDefinitions();
$lbb_entity_type = $entity_manager
->getDefinition('layout_builder_browser_block');
if ($lbb_entity_type && $lbb_entity_type instanceof \Drupal\Core\Entity\EntityTypeInterface) {
\Drupal::entityDefinitionUpdateManager()
->installEntityType($lbb_entity_type);
}
}
Functions
Name | Description |
---|---|
layout_builder_browser_update_8001 | Migrate layout builder blocks to be config entities on their own. |
layout_builder_browser_update_8002 | #3184784: Ensure block config entity is installed on existing sites. |