Commit 8d0d69f0 authored by alexpott's avatar alexpott

Issue #2753939 by phenaproxima, alexpott: BlockRegion process plugin should be source theme-aware

parent 4338fa0b
......@@ -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
......
......@@ -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
......
......@@ -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);
}
}
......@@ -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 = [];
......
......@@ -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');
......
......@@ -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']));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment