diff --git a/core/modules/block/migration_templates/d6_block.yml b/core/modules/block/migration_templates/d6_block.yml
index 8be753974d03a51dbb26e592ed727e46b704e1ef..472d48d78be4ec07faa8aaa4299cc8f876a385bf 100644
--- a/core/modules/block/migration_templates/d6_block.yml
+++ b/core/modules/block/migration_templates/d6_block.yml
@@ -63,17 +63,19 @@ process:
region:
plugin: block_region
source:
- - region
- theme
- '@theme'
- region_map:
- left: sidebar_first
- right: sidebar_second
- sidebar_first: sidebar_first
- sidebar_second: sidebar_second
- help: help
- header: header
- footer: footer
+ - region
+ map:
+ garland:
+ bartik:
+ # Garland 6.x --> Bartik 8.x
+ header: header
+ footer: footer_fifth
+ left: sidebar_first
+ right: sidebar_second
+ # If mapping fails, put the block in the content region.
+ default_value: content
weight: weight
settings:
plugin: block_settings
diff --git a/core/modules/block/migration_templates/d7_block.yml b/core/modules/block/migration_templates/d7_block.yml
index ff561118e866f4b40921305bbde8e522c102798e..96b204eaa55f9a5d0fb86c51e1ee37b16919bcb7 100644
--- a/core/modules/block/migration_templates/d7_block.yml
+++ b/core/modules/block/migration_templates/d7_block.yml
@@ -67,17 +67,24 @@ process:
region:
plugin: block_region
source:
- - region
- theme
- '@theme'
- region_map:
- left: sidebar_first
- right: sidebar_second
- sidebar_first: sidebar_first
- sidebar_second: sidebar_second
- help: help
- header: header
- footer: footer
+ - region
+ map:
+ bartik:
+ bartik:
+ # Bartik 7.x --> Bartik 8.x
+ featured: featured_top
+ triptych_first: featured_bottom_first
+ triptych_middle: featured_bottom_second
+ triptych_last: featured_bottom_third
+ footer_firstcolumn: footer_first
+ footer_secondcolumn: footer_second
+ footer_thirdcolumn: footer_third
+ footer_fourthcolumn: footer_fourth
+ footer: footer_fifth
+ # If mapping fails, put the block in the content region.
+ default_value: content
weight: weight
settings:
plugin: block_settings
diff --git a/core/modules/block/src/Plugin/migrate/process/BlockRegion.php b/core/modules/block/src/Plugin/migrate/process/BlockRegion.php
index d05743e68299d9272ac3caae977e5eded2cf54b0..8aba3ee84cb49074a54276e497dc8ae543b22170 100644
--- a/core/modules/block/src/Plugin/migrate/process/BlockRegion.php
+++ b/core/modules/block/src/Plugin/migrate/process/BlockRegion.php
@@ -4,7 +4,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
-use Drupal\migrate\ProcessPluginBase;
+use Drupal\migrate\Plugin\migrate\process\StaticMap;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -13,7 +13,7 @@
* id = "block_region"
* )
*/
-class BlockRegion extends ProcessPluginBase implements ContainerFactoryPluginInterface {
+class BlockRegion extends StaticMap implements ContainerFactoryPluginInterface {
/**
* List of regions, keyed by theme.
@@ -56,7 +56,7 @@ public static function create(ContainerInterface $container, array $configuratio
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Set the destination region, based on the source region and theme as well
// as the current destination default theme.
- list($region, $source_theme, $destination_theme) = $value;
+ list($source_theme, $destination_theme, $region) = $value;
// Theme is the same on both source and destination, so ensure that the
// region exists in the destination theme.
@@ -66,15 +66,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
}
}
- // If the source and destination theme are different, try to use the
- // mappings defined in the configuration.
- $region_map = $this->configuration['region_map'];
- if (isset($region_map[$region])) {
- return $region_map[$region];
- }
-
- // Oh well, we tried. Put the block in the main content region.
- return 'content';
+ // Fall back to static mapping.
+ return parent::transform($value, $migrate_executable, $row, $destination_property);
}
}
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
index bc59f71828721cd20e4e1acd62a7353014f7a4e5..c5dfba21c397796c19ec83b8abd4e6879819ec7c 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
@@ -50,6 +50,7 @@ protected function setUp() {
'd6_user_role',
'd6_block',
]);
+ block_rebuild();
}
/**
@@ -69,19 +70,21 @@ protected function setUp() {
* The block label.
* @param string $label_display
* The block label display setting.
+ * @param bool $status
+ * Whether the block is expected to be enabled or disabled.
*/
public function assertEntity($id, $visibility, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
$block = Block::load($id);
$this->assertTrue($block instanceof Block);
- $this->assertIdentical($visibility, $block->getVisibility());
- $this->assertIdentical($region, $block->getRegion());
- $this->assertIdentical($theme, $block->getTheme());
- $this->assertIdentical($weight, $block->getWeight());
- $this->assertIdentical($status, $block->status());
+ $this->assertSame($visibility, $block->getVisibility());
+ $this->assertSame($region, $block->getRegion());
+ $this->assertSame($theme, $block->getTheme());
+ $this->assertSame($weight, $block->getWeight());
+ $this->assertSame($status, $block->status());
$config = $this->config('block.block.' . $id);
- $this->assertIdentical($label, $config->get('settings.label'));
- $this->assertIdentical($label_display, $config->get('settings.label_display'));
+ $this->assertSame($label, $config->get('settings.label'));
+ $this->assertSame($label_display, $config->get('settings.label_display'));
}
/**
@@ -124,9 +127,7 @@ public function testBlockMigration() {
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = TRUE;
$visibility['request_path']['pages'] = '/node/1';
- // @todo https://www.drupal.org/node/2753939 This block is the footer region
- // but Bartik in D8 does not have this region.
- $this->assertEntity('system', $visibility, 'header', 'bartik', -5, '', '0', FALSE);
+ $this->assertEntity('system', $visibility, 'footer_fifth', 'bartik', -5, '', '0');
// Check menu blocks
$visibility = [];
@@ -141,8 +142,8 @@ public function testBlockMigration() {
$visibility['request_path']['id'] = 'request_path';
$visibility['request_path']['negate'] = FALSE;
$visibility['request_path']['pages'] = '/node';
- // @todo https://www.drupal.org/node/2753939 The bluemarine theme does not
- // exist.
+ // We expect this block to be disabled because '' is not a valid region,
+ // and block_rebuild() will disable any block in an invalid region.
$this->assertEntity('block_1', $visibility, '', 'bluemarine', -4, 'Another Static Block', 'visible', FALSE);
$visibility = [];
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
index b98f46f1cf5de746e68018f146548fa9b1c6c65c..6f07dc9c21e7bc38f865e94d2b2ba48574f2e9ff 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
@@ -54,6 +54,7 @@ protected function setUp() {
'd7_custom_block',
'd7_block',
]);
+ block_rebuild();
}
/**
@@ -77,30 +78,32 @@ protected function setUp() {
* The block label.
* @param string $label_display
* The block label display setting.
+ * @param bool $status
+ * Whether the block is expected to be enabled or disabled.
*/
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
$block = Block::load($id);
$this->assertTrue($block instanceof Block);
/** @var \Drupal\block\BlockInterface $block */
- $this->assertIdentical($plugin_id, $block->getPluginId());
+ $this->assertSame($plugin_id, $block->getPluginId());
$visibility = $block->getVisibility();
if ($roles) {
- $this->assertIdentical($roles, array_values($visibility['user_role']['roles']));
- $this->assertIdentical('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
+ $this->assertSame($roles, array_values($visibility['user_role']['roles']));
+ $this->assertSame('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
}
if ($pages) {
- $this->assertIdentical($pages, $visibility['request_path']['pages']);
+ $this->assertSame($pages, $visibility['request_path']['pages']);
}
- $this->assertIdentical($region, $block->getRegion());
- $this->assertIdentical($theme, $block->getTheme());
- $this->assertIdentical($weight, $block->getWeight());
- $this->assertIdentical($status, $block->status());
+ $this->assertSame($region, $block->getRegion());
+ $this->assertSame($theme, $block->getTheme());
+ $this->assertSame($weight, $block->getWeight());
+ $this->assertSame($status, $block->status());
$config = $this->config('block.block.' . $id);
- $this->assertIdentical($label, $config->get('settings.label'));
- $this->assertIdentical($label_display, $config->get('settings.label_display'));
+ $this->assertSame($label, $config->get('settings.label'));
+ $this->assertSame($label_display, $config->get('settings.label_display'));
}
/**
@@ -110,9 +113,7 @@ public function testBlockMigration() {
$this->assertEntity('bartik_system_main', 'system_main_block', [], '', 'content', 'bartik', 0, '', '0');
$this->assertEntity('bartik_search_form', 'search_form_block', [], '', 'sidebar_first', 'bartik', -1, '', '0');
$this->assertEntity('bartik_user_login', 'user_login_block', [], '', 'sidebar_first', 'bartik', 0, '', '0');
- // @todo https://www.drupal.org/node/2753939 This block is the footer region
- // but Bartik in D8 does not have this region.
- $this->assertEntity('bartik_system_powered_by', 'system_powered_by_block', [], '', 'header', 'bartik', 10, '', '0', FALSE);
+ $this->assertEntity('bartik_system_powered_by', 'system_powered_by_block', [], '', 'footer_fifth', 'bartik', 10, '', '0');
$this->assertEntity('seven_system_main', 'system_main_block', [], '', 'content', 'seven', 0, '', '0');
$this->assertEntity('seven_user_login', 'user_login_block', [], '', 'content', 'seven', 10, '', '0');
diff --git a/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockRegionTest.php b/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockRegionTest.php
index 8194709eb6e6b0bcfd544bce44110a9372a38621..f473dc4c83c27ac56609c9ad17eb59f1b64e93f4 100644
--- a/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockRegionTest.php
+++ b/core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockRegionTest.php
@@ -30,14 +30,20 @@ protected function transform(array $value, Row $row = NULL) {
$row = $this->prophesize(Row::class)->reveal();
}
- $regions = array(
- 'bartik' => array(
- 'triptych_first' => 'Triptych first',
- 'triptych_second' => 'Triptych second',
- 'triptych_third' => 'Triptych third',
- ),
- );
- $plugin = new BlockRegion(['region_map' => []], 'block_region', [], $regions);
+ $configuration = [
+ 'map' => [
+ 'bartik' => [
+ 'bartik' => [
+ 'triptych_first' => 'triptych_first',
+ 'triptych_middle' => 'triptych_second',
+ 'triptych_last' => 'triptych_third',
+ ],
+ ],
+ ],
+ 'default_value' => 'content',
+ ];
+
+ $plugin = new BlockRegion($configuration, 'block_region', [], $configuration['map']['bartik']['bartik']);
return $plugin->transform($value, $executable, $row, 'foo');
}
@@ -48,7 +54,7 @@ protected function transform(array $value, Row $row = NULL) {
* @covers ::transform
*/
public function testTransformSameThemeRegionExists() {
- $this->assertSame('triptych_second', $this->transform(['triptych_second', 'bartik', 'bartik']));
+ $this->assertSame('triptych_second', $this->transform(['bartik', 'bartik', 'triptych_middle']));
}
/**
@@ -58,7 +64,7 @@ public function testTransformSameThemeRegionExists() {
* @covers ::transform
*/
public function testTransformSameThemeRegionNotExists() {
- $this->assertSame('content', $this->transform(['footer', 'bartik', 'bartik']));
+ $this->assertSame('content', $this->transform(['bartik', 'bartik', 'footer']));
}
}