function domain_update_8002 in Domain Access 8
Updates block domain context_mapping for Drupal 8.8 and higher.
1 call to domain_update_8002()
- domain_update_8003 in domain/
domain.install - Ensure that the update to block visibility was applied properly.
File
- domain/
domain.install, line 57 - Install, update and uninstall functions for the Domain Access module.
Code
function domain_update_8002() {
$new_context_id = '@domain.current_domain_context:domain';
$config_factory = \Drupal::configFactory();
$update_list = [];
foreach ($config_factory
->listAll('block.block.') as $block_config_name) {
$update_block = FALSE;
$block = $config_factory
->getEditable($block_config_name);
if ($visibility = $block
->get('visibility')) {
foreach ($visibility as $condition_plugin_id => &$condition) {
if ($condition_plugin_id == 'domain' && (empty($condition['context_mapping']['domain']) || $condition['context_mapping']['domain'] !== $new_context_id)) {
$condition['context_mapping']['domain'] = $new_context_id;
$update_block = TRUE;
$update_list[] = $block_config_name;
}
}
}
if ($update_block) {
$block
->set('visibility', $visibility);
$block
->save(TRUE);
}
}
if (empty($update_list)) {
return t('No blocks updated.');
}
else {
return t('Updated @count blocks: @blocks', [
'@count' => count($update_list),
'@blocks' => implode(', ', $update_list),
]);
}
}