diff --git a/core/modules/block/block.install b/core/modules/block/block.install index 99ce4ef..a831fcb 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -45,8 +45,9 @@ function block_update_8001() { } // Contributed modules should leverage hook_update_dependencies() in order to - // be executed before block_update_8002(), so they can update their context - // mappings, if wanted. + // be executed after block_update_8001(). The blocks are then disabled if the + // contexts are still missing via + // block_post_update_disable_blocks_with_missing_contexts(). $config_factory = \Drupal::configFactory(); $backup_values = $update_backup = []; @@ -95,52 +96,5 @@ function block_update_8001() { } /** - * Disable all blocks with missing context IDs in block_update_8001(). - */ -function block_update_8002() { - $block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []); - - $block_ids = array_keys($block_update_8001); - $config_factory = \Drupal::configFactory(); - /** @var \Drupal\Core\Config\Config[] $blocks */ - $blocks = []; - foreach ($block_ids as $block_id) { - $blocks[$block_id] = $block = $config_factory->getEditable('block.block.' . $block_id); - // This block will have an invalid context mapping service and must be - // disabled in order to prevent information disclosure. - - // Disable currently enabled blocks. - if ($block_update_8001[$block_id]['status']) { - $block->set('status', FALSE); - $block->save(TRUE); - } - } - - // Provides a list of plugin labels, keyed by plugin ID. - $condition_plugin_id_label_map = array_column(\Drupal::service('plugin.manager.condition')->getDefinitions(), 'label', 'id'); - - // Override with the UI labels we are aware of. Sadly they are not machine - // accessible, see - // \Drupal\node\Plugin\Condition\NodeType::buildConfigurationForm(). - $condition_plugin_id_label_map['node_type'] = t('Content types'); - $condition_plugin_id_label_map['request_path'] = t('Pages'); - $condition_plugin_id_label_map['user_role'] = t('Roles'); - - if (count($block_ids) > 0) { - $message = t('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); - $message .= ''; - - return $message; - } -} - -/** * @} End of "addtogroup updates-8.0.0-beta". */ diff --git a/core/modules/block/block.post_update.php b/core/modules/block/block.post_update.php new file mode 100644 index 0000000..e4079eb --- /dev/null +++ b/core/modules/block/block.post_update.php @@ -0,0 +1,61 @@ +get('block_update_8001', []); + + $block_ids = array_keys($block_update_8001); + $block_storage = \Drupal::entityManager()->getStorage('block'); + $blocks = $block_storage->loadMultiple($block_ids); + foreach ($blocks as $block) { + /** @var $block \Drupal\block\BlockInterface */ + // This block will have an invalid context mapping service and must be + // disabled in order to prevent information disclosure. + + // Disable currently enabled blocks. + if ($block_update_8001[$block->id()]['status']) { + $block->setStatus(FALSE); + $block->save(); + } + } + + // Provides a list of plugin labels, keyed by plugin ID. + $condition_plugin_id_label_map = array_column(\Drupal::service('plugin.manager.condition')->getDefinitions(), 'label', 'id'); + + // Override with the UI labels we are aware of. Sadly they are not machine + // accessible, see + // \Drupal\node\Plugin\Condition\NodeType::buildConfigurationForm(). + $condition_plugin_id_label_map['node_type'] = t('Content types'); + $condition_plugin_id_label_map['request_path'] = t('Pages'); + $condition_plugin_id_label_map['user_role'] = t('Roles'); + + if (count($block_ids) > 0) { + $message = t('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); + $message .= ''; + + return $message; + } +} + +/** + * @} End of "addtogroup updates-8.0.0-beta". + */