diff --git a/core/modules/block/block.install b/core/modules/block/block.install index 3bf0cce..b39888b 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -33,20 +33,16 @@ function block_update_8001() { // value to another value. In this update function however, we deal with // converting the format of the context_mapping, which makes code reacting // to Entity API hooks tricky, because they would need to be different for - // before/after the update. - // We also doesn't use the Drupal config API (\Drupal::configFactory()) as - // this triggers events, which has similar problems. - // For updating the status flag of the block in the next update function, - // however, we can use Entity API. + // before/after the update. For updating the status flag of the block in the + // next update function, however, we can use Entity API. // Contributed modules should leverage hook_update_dependencies() in order to // be executed before block_update_8002(). - /** @var \Drupal\Core\Config\StorageInterface $config_storage */ - $config_storage = \Drupal::service('config.storage'); + $config_factory = \Drupal::configFactory(); $backup_values = $update_backup = []; - foreach ($config_storage->listAll('block.block.') as $block_config_name) { - $block = $config_storage->read($block_config_name); - if ($visibility = $block['visibility']) { + foreach ($config_factory->listAll('block.block.') as $block_config_name) { + $block = $config_factory->getEditable($block_config_name); + if ($visibility = $block->get('visibility')) { foreach ($visibility as $condition_plugin_id => &$condition) { foreach ($condition['context_mapping'] as $key => $context) { if (!isset($context_service_id_map[$key])) { @@ -65,7 +61,7 @@ function block_update_8001() { $condition['context_mapping'][$key] = '@' . $context_service_id_map[$key] . ':' . $new_context_id[1]; } } - $block['visibility'] = $visibility; + $block->set('visibility', $visibility); if ($backup_values) { // We not only store the missing context mappings but also the previous @@ -75,7 +71,9 @@ function block_update_8001() { } } - $config_storage->write($block_config_name, $block); + // Use the trusted data feature during hook_update_N() to mitigate issues + // with schema changes. + $block->save(TRUE); } if ($update_backup) {