diff --git a/core/modules/block/block.install b/core/modules/block/block.install index de652be..c0971c3 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -21,20 +21,27 @@ function block_update_8001() { 'user' => 'user.current_user_context', ]; + // Provides a hardcoded list of UI labels for each condition plugins. Sadly + // they are not machine accessible, see + // \Drupal\node\Plugin\Condition\NodeType::buildConfigurationForm. $condition_plugin_id_ui_label_map = [ 'node_type' => \Drupal::translation()->translate('Content types'), 'request_path' => \Drupal::translation()->translate('Pages'), 'user_role' => \Drupal::translation()->translate('Roles'), ]; - $config_factory = \Drupal::configFactory(); - $message = NULL; - $disabled_blocks = $problematic_visibility_plugins = $backup_values = []; + $condition_plugin_id_label_map = array_map(function($definition) { + return $definition['label']; + }, \Drupal::service('plugin.manager.condition')->getDefinitions()); + // We deal with config objects directly in order to avoid invoking Entity API // hooks. They can be problematic when two modules implement a specific hook, // their code is updated at the same time, yet the update functions run // sequentially so the second hook implementation can not rely on the data not // being altered by the first hook. + $config_factory = \Drupal::configFactory(); + $message = NULL; + $disabled_blocks = $problematic_visibility_plugins = $backup_values = []; $update_backup = []; foreach ($config_factory->listAll('block.block.') as $block_config_name) { @@ -49,7 +56,7 @@ function block_update_8001() { // modules can run their own update functions to update mappings // that they provide. $disabled_blocks[$block->get('id')] = $block->get('settings.label'); - $problematic_visibility_plugins[$block->get('id')][] = $condition_plugin_id_ui_label_map[$condition_plugin_id]; + $problematic_visibility_plugins[$block->get('id')][] = isset($condition_plugin_id_ui_label_map[$condition_plugin_id]) ? $condition_plugin_id_ui_label_map[$condition_plugin_id] : $condition_plugin_id_label_map[$condition_plugin_id]; $backup_values[] = $context; unset($visibility[$condition_plugin_id]); @@ -61,8 +68,7 @@ function block_update_8001() { } if (isset($disabled_blocks[$block->get('id')])) { // This block will have an invalid context mapping service and must be - // disabled to avoid the 'You must provide the context IDs in the - // @{service_id}:{unqualified_context_id} format' exception. + // disabled in order to prevent information disclosure. $block->set('status', FALSE); } $block->set('visibility', $visibility); @@ -80,10 +86,10 @@ function block_update_8001() { } if ($disabled_blocks) { - $message = \Drupal::translation()->translate('Encountered an unexpected context mapping key, one or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); + $message = \Drupal::translation()->translate('Encountered a context mapping key coming probably from a contrib module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); $message .= ''; } diff --git a/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php b/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php index e05efb7..5a10a69 100644 --- a/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php +++ b/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php @@ -32,11 +32,11 @@ protected function setUp() { } /** - * Tests that block context mapping are updated properly. + * Tests that block context mapping is updated properly. */ public function testUpdateHookN() { $this->runUpdates(); - $this->assertRaw('Encountered an unexpected context mapping key, one or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); + $this->assertRaw('Encountered a context mapping key coming probably from a contrib module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:'); // Disable maintenance mode. \Drupal::state()->set('system.maintenance_mode', FALSE);