blockgroup.install in Block Group 8
Blockgroup install file.
File
blockgroup.installView source
<?php
/**
* @file
* Blockgroup install file.
*/
/**
* Updated blockgroup plugin IDs in block placements.
*/
function blockgroup_update_8100() {
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$config_factory = \Drupal::configFactory();
$update_count = 0;
foreach ($config_factory
->listAll('block.block.') as $config_name) {
$config = $config_factory
->getEditable($config_name);
$needs_save = FALSE;
foreach ([
'plugin',
'settings.id',
] as $key) {
$value = $config
->get($key);
$parts = explode(':', $value, 2);
if (count($parts) === 2 && $parts[0] === 'block_group') {
$block_group = $entity_repository
->loadEntityByUuid('block_group_content', $parts[1]);
$block_group_id = $block_group
->id();
$new_value = "block_group:{$block_group_id}";
$config
->set($key, $new_value);
$update_count += 1;
$needs_save = TRUE;
}
}
// Mark as trusted to not trigger further processing.
if ($needs_save) {
$config
->save(TRUE);
}
}
return "Updated {$update_count} blockgroup plugin IDs (2 per block) in block placements.";
}
Functions
Name | Description |
---|---|
blockgroup_update_8100 | Updated blockgroup plugin IDs in block placements. |