commit 2ccdf89e26639effeab861e656c431b5ef120dd9 Author: Lee Rowlands Date: Wed Jul 8 09:52:03 2015 +1000 p19 diff --git a/core/modules/block/block.install b/core/modules/block/block.install index 60fbdfe..645f357 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -21,9 +21,11 @@ function block_update_8001() { ]; $config_factory = \Drupal::configFactory(); + $message = NULL; foreach ($config_factory->listAll('block.block.') as $block_config_name) { // We deal with config objects directly to avoid the config entity API. $block = $config_factory->getEditable($block_config_name); + $disable_block = FALSE; if ($visibility = $block->get('visibility')) { foreach ($visibility as &$condition) { foreach ($condition['context_mapping'] as $key => $context) { @@ -32,19 +34,26 @@ function block_update_8001() { // and users can fix their block placements manually OR // alternatively contrib modules can run their own update functions // to update mappings that they provide. - drupal_set_message(\Drupal::translation()->translate('Encountered an unexpected context mapping key, one or more mappings could not be updated. Please manually review your block placements.'), 'error'); + $message = \Drupal::translation()->translate('Encountered an unexpected context mapping key, one or more mappings could not be updated. Please manually review your block placements.'); + $disable_block = TRUE; continue; } $new_context_id = explode('.', $context, 2); $condition['context_mapping'][$key] = '@' . $context_service_id_map[$key] . ':' . $new_context_id[1]; } } - + if ($disable_block) { + // 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. + $block->set('status', FALSE); + } $block->set('visibility', $visibility); } $block->save(); } + return $message; } /** diff --git a/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php b/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php index 29c25aa..1a89537 100644 --- a/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php +++ b/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php @@ -35,6 +35,7 @@ protected function setUp() { */ public function testUpdateHookN() { $this->runUpdates(); + $this->assertText(t('Encountered an unexpected context mapping key, one or more mappings could not be updated. Please manually review your block placements.')); // Disable maintenance mode. \Drupal::state()->set('system.maintenance_mode', FALSE); diff --git a/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php b/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php index 34a810b..0ad77c5 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php @@ -99,6 +99,47 @@ 'status' => TRUE, ], 'visibility' => [], +],[ + 'uuid' => '4558907D-2918-48FE-B56F-8A007B5FBDD5', + 'langcode' => 'en', + 'status' => TRUE, + 'dependencies' => [ + 'module' => [ + 'user', + ], + 'theme' => [ + 'bartik', + ], + ], + 'id' => 'thirdtestfor2354889', + 'theme' => 'bartik', + 'region' => 'sidebar_first', + 'weight' => -6, + 'provider' => NULL, + 'plugin' => 'user_login_block', + 'settings' => [ + 'id' => 'user_login_block', + 'label' => 'User login', + 'provider' => 'user', + 'label_display' => 'visible', + 'cache' => [ + 'max_age' => -1, + ], + 'status' => TRUE, + ], + 'visibility' => [ + 'node_type' => [ + 'id' => 'node_type', + 'bundles' => [ + 'page' => 'page', + ], + 'negate' => FALSE, + // Non-existent mapping that will be tested. + 'context_mapping' => [ + 'baloney' => 'baloney.spam', + ], + ], + ], ]]; foreach ($block_configs as $block_config) {