diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml index 55448b8261a85861f53107e987a517d42c4f6ac4..e148c6e541d4f10a002b42cc2ecd4db07214ecd7 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml @@ -3,6 +3,11 @@ label: Drupal 6 blocks source: plugin: d6_block process: + # Drupal 8 does not have a status but it doesn't matter; this is here to + # skip disabled blocks. + status: + plugin: skip_row_on_empty + source: status id: # We need something unique, so aggregator, aggregator_1 etc will do. plugin: dedupe_entity @@ -43,8 +48,26 @@ process: 3: views_block:who_s_online-who_s_online_block - plugin: d6_block_plugin_id - region: region - theme: theme + theme: + plugin: d6_block_theme + source: + - theme + - default_theme + - admin_theme + region: + plugin: d6_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 label: title weight: weight settings: @@ -59,7 +82,6 @@ process: destination: plugin: entity:block migration_dependencies: - required: - - d6_custom_block optional: - d6_menu + - d6_custom_block diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_theme.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_theme.yml deleted file mode 100644 index 65b10cb143216dd09dce3b431e3b09b2baf99cba..0000000000000000000000000000000000000000 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_theme.yml +++ /dev/null @@ -1,13 +0,0 @@ -id: d6_system_theme -label: Drupal 6 theme configuration -source: - plugin: variable - variables: - - admin_theme - - theme_default -process: - admin: admin_theme - default: theme_default -destination: - plugin: config - config_name: system.theme diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/BlockRegion.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/BlockRegion.php new file mode 100644 index 0000000000000000000000000000000000000000..fd797f00cf3d57ada367ef7ebedc15350cde8332 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/BlockRegion.php @@ -0,0 +1,46 @@ +<?php +/** + * @file + * Contains \Drupal\migrate_drupal\Plugin\migrate\Process\d6\BlockRegion. + */ + +namespace Drupal\migrate_drupal\Plugin\migrate\Process\d6; + +use Drupal\Component\Utility\NestedArray; +use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\ProcessPluginBase; +use Drupal\migrate\Row; + +/** + * @MigrateProcessPlugin( + * id = "d6_block_region" + * ) + */ +class BlockRegion extends ProcessPluginBase { + /** + * {@inheritdoc} + * + * Set the destination block region, based on the source region and theme as + * well as the current destination default theme. + */ + public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) { + list($region, $source_theme, $destination_theme) = $value; + + // Theme is the same on both source and destination, we will assume they + // have the same regions. + if (strtolower($source_theme) == strtolower($destination_theme)) { + return $region; + } + + // 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'; + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/BlockTheme.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/BlockTheme.php new file mode 100644 index 0000000000000000000000000000000000000000..39239cfa795f6fd53b38645c3d8f848e10bfa3db --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/BlockTheme.php @@ -0,0 +1,103 @@ +<?php +/** + * @file + * Contains \Drupal\migrate_drupal\Plugin\migrate\Process\d6\BlockTheme. + */ + +namespace Drupal\migrate_drupal\Plugin\migrate\Process\d6; + +use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\ProcessPluginBase; +use Drupal\migrate\Row; +use Drupal\Core\Config\Config; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * @MigrateProcessPlugin( + * id = "d6_block_theme" + * ) + */ +class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInterface { + + /** + * Contains the configuration object factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + + /** + * Contains the system.theme configuration object. + * + * @var \Drupal\Core\Config\Config + */ + protected $themeConfig; + + /** + * Constructs a BlockTheme object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\migrate\Entity\MigrationInterface $migration + * The migration entity. + * @param \Drupal\Core\Config\Config $theme_config + * The system.theme configuration factory object. + * @param array $themes + * The list of themes available on the destination. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Config $theme_config, array $themes) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + $this->themeConfig = $theme_config; + $this->themes = $themes; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('config.factory')->get('system.theme'), + $container->get('theme_handler')->listInfo() + ); + } + + /** + * {@inheritdoc} + * + * Set the block theme, based on the current default theme. + */ + public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) { + list($theme, $d6_default_theme, $d6_admin_theme) = $value; + + // If the source theme exists on the destination, we're good. + if (isset($this->themes[$theme])) { + return $theme; + } + + // If the source block is assigned to a region in the source default theme, + // then assign it to the destination default theme. + if (strtolower($theme) == strtolower($d6_default_theme)) { + return $this->themeConfig->get('default'); + } + + // If the source block is assigned to a region in the source admin theme, + // then assign it to the destination admin theme. + if (strtolower($theme) == strtolower($d6_admin_theme)) { + return $this->themeConfig->get('admin'); + } + + // We couldn't map it to a D8 theme so just return the incoming theme. + return $theme; + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Block.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Block.php index dbc58a9066de79dd982eb2fdb707699aac8424f8..9bca13ee5b39559b7850d122c1f4b944ba0be610 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Block.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/Block.php @@ -18,6 +18,19 @@ * ) */ class Block extends DrupalSqlBase { + /** + * The default theme name. + * + * @var string + */ + protected $defaultTheme; + + /** + * The admin theme name. + * + * @var string + */ + protected $adminTheme; /** * {@inheritdoc} @@ -29,6 +42,15 @@ public function query() { return $query; } + /** + * {@inheritdoc} + */ + protected function runQuery() { + $this->defaultTheme = $this->variableGet('theme_default', 'Garland'); + $this->adminTheme = $this->variableGet('admin_theme', null); + return parent::runQuery(); + } + /** * {@inheritdoc} */ @@ -53,6 +75,8 @@ public function fields() { * {@inheritdoc} */ public function prepareRow(Row $row) { + $row->setSourceProperty('default_theme', $this->defaultTheme); + $row->setSourceProperty('admin_theme', $this->adminTheme); $module = $row->getSourceProperty('module'); $delta = $row->getSourceProperty('delta'); $roles = $this->select('blocks_roles', 'br') @@ -63,8 +87,8 @@ public function prepareRow(Row $row) { ->fetchCol(); $row->setSourceProperty('permissions', $roles); $settings = array(); - // Contrib can use hook_migration_d6_block_prepare_row() to add similar variables - // via $migration->getSource()->variableGet(). + // Contrib can use hook_migration_d6_block_prepare_row() to add similar + // variables via $migration->getSource()->variableGet(). switch ($module) { case 'aggregator': list($type, $id) = explode('-', $delta); diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Block.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Block.php index cb3c9d976bb9b8c3b41bc2e06cc1ba72ced21df4..fa678550fd0eca2558283a2df1b251d3991db7a3 100644 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Block.php +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Block.php @@ -170,7 +170,7 @@ public function load() { 'pages' => '', 'title' => '', 'cache' => '-1' - )) + )) ->values(array( 'bid' => '2', 'module' => 'user', @@ -321,6 +321,36 @@ public function load() { 'title' => 'Another Static Block', 'cache' => '-1' )) + ->values(array( + 'bid' => '12', + 'module' => 'block', + 'delta' => '1', + 'theme' => 'test_theme', + 'status' => '1', + 'weight' => '-7', + 'region' => 'right', + 'custom' => '0', + 'throttle' => '0', + 'visibility' => '0', + 'pages' => '', + 'title' => '', + 'cache' => '-1' + )) + ->values(array( + 'bid' => '13', + 'module' => 'block', + 'delta' => '2', + 'theme' => 'test_theme', + 'status' => '1', + 'weight' => '-2', + 'region' => 'left', + 'custom' => '0', + 'throttle' => '0', + 'visibility' => '0', + 'pages' => '', + 'title' => '', + 'cache' => '-1' + )) ->execute(); } } diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6SystemTheme.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6SystemTheme.php deleted file mode 100644 index 9b9ceb3297eaabca24d4af9ed86f21f3a1bda252..0000000000000000000000000000000000000000 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6SystemTheme.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate_drupal\Tests\Dump\Drupal6SystemTheme. - */ - -namespace Drupal\migrate_drupal\Tests\Dump; - -/** - * Database dump for testing system.theme.yml migration. - */ -class Drupal6SystemTheme extends Drupal6DumpBase { - - /** - * {@inheritdoc} - */ - public function load() { - $this->createTable('variable'); - $this->database->insert('variable')->fields(array( - 'name', - 'value', - )) - ->values(array( - 'name' => 'admin_theme', - 'value' => 'i:0;', - )) - ->values(array( - 'name' => 'theme_default', - 'value' => 's:7:"garland";', - )) - ->execute(); - } - -} diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php index 2a3d3304008d58759aa9ba8516c8c098e1968178..1618d1e27ea2c1b6ac827b897c5eb553b4c71e6d 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php @@ -50,8 +50,20 @@ public function setUp() { 'd6_custom_block' => array( array(array(10), array(1)), array(array(11), array(2)), + array(array(12), array(1)), + array(array(13), array(2)), ) )); + + // Set Bartik and Seven as the default public and admin theme. + $config = \Drupal::config('system.theme'); + $config->set('default', 'bartik'); + $config->set('admin', 'seven'); + $config->save(); + + // Enable one of D8's test themes. + \Drupal::service('theme_handler')->enable(array('test_theme')); + /** @var \Drupal\migrate\entity\Migration $migration */ $migration = entity_load('migration', 'd6_block'); $dumps = array( @@ -68,13 +80,13 @@ public function setUp() { public function testBlockMigration() { /** @var $blocks \Drupal\block\BlockInterface[] */ $blocks = entity_load_multiple('block'); - $this->assertEqual(count($blocks), 11); + $this->assertEqual(count($blocks), 8); // User blocks $test_block_user = $blocks['user']; $this->assertNotNull($test_block_user); - $this->assertEqual('left', $test_block_user->get('region')); - $this->assertEqual('garland', $test_block_user->get('theme')); + $this->assertEqual('sidebar_first', $test_block_user->get('region')); + $this->assertEqual('bartik', $test_block_user->get('theme')); $visibility = $test_block_user->getVisibility(); $this->assertEqual(TRUE, $visibility['request_path']['negate']); $this->assertEqual('', $visibility['request_path']['pages']); @@ -82,85 +94,38 @@ public function testBlockMigration() { $test_block_user_1 = $blocks['user_1']; $this->assertNotNull($test_block_user_1); - $this->assertEqual('left', $test_block_user_1->get('region')); - $this->assertEqual('garland', $test_block_user_1->get('theme')); + $this->assertEqual('sidebar_first', $test_block_user_1->get('region')); + $this->assertEqual('bartik', $test_block_user_1->get('theme')); $visibility = $test_block_user_1->getVisibility(); $this->assertEqual(TRUE, $visibility['request_path']['negate']); $this->assertEqual('', $visibility['request_path']['pages']); $this->assertEqual(0, $test_block_user_1->weight); - $test_block_user_2 = $blocks['user_2']; - $this->assertNotNull($test_block_user_2); - $this->assertEqual('', $test_block_user_2->get('region')); - $this->assertEqual('garland', $test_block_user_2->get('theme')); - $visibility = $test_block_user_2->getVisibility(); - $this->assertEqual(TRUE, $visibility['request_path']['negate']); - $this->assertEqual('', $visibility['request_path']['pages']); - $this->assertEqual(-3, $test_block_user_2->weight); - - $test_block_user_3 = $blocks['user_3']; - $this->assertNotNull($test_block_user_3); - $this->assertEqual('', $test_block_user_3->get('region')); - $this->assertEqual('garland', $test_block_user_3->get('theme')); - $visibility = $test_block_user_3->getVisibility(); - $this->assertEqual(TRUE, $visibility['request_path']['negate']); - $this->assertEqual('', $visibility['request_path']['pages']); - $this->assertEqual(-1, $test_block_user_3->weight); - // Check system block $test_block_system = $blocks['system']; $this->assertNotNull($test_block_system); $this->assertEqual('footer', $test_block_system->get('region')); - $this->assertEqual('garland', $test_block_system->get('theme')); + $this->assertEqual('bartik', $test_block_system->get('theme')); $visibility = $test_block_system->getVisibility(); $this->assertEqual(TRUE, $visibility['request_path']['negate']); $this->assertEqual('', $visibility['request_path']['pages']); $this->assertEqual(-5, $test_block_system->weight); - // Check comment block - $test_block_comment = $blocks['comment']; - $this->assertNotNull($test_block_comment); - $this->assertEqual('', $test_block_comment->get('region')); - $this->assertEqual('garland', $test_block_comment->get('theme')); - $visibility = $test_block_comment->getVisibility(); - $this->assertEqual(TRUE, $visibility['request_path']['negate']); - $this->assertEqual('', $visibility['request_path']['pages']); - $this->assertEqual(-6, $test_block_comment->weight); - // Check menu blocks $test_block_menu = $blocks['menu']; $this->assertNotNull($test_block_menu); $this->assertEqual('header', $test_block_menu->get('region')); - $this->assertEqual('garland', $test_block_menu->get('theme')); + $this->assertEqual('bartik', $test_block_menu->get('theme')); $visibility = $test_block_menu->getVisibility(); $this->assertEqual(TRUE, $visibility['request_path']['negate']); $this->assertEqual('', $visibility['request_path']['pages']); $this->assertEqual(-5, $test_block_menu->weight); - $test_block_menu_1 = $blocks['menu_1']; - $this->assertNotNull($test_block_menu_1); - $this->assertEqual('', $test_block_menu_1->get('region')); - $this->assertEqual('garland', $test_block_menu_1->get('theme')); - $visibility = $test_block_menu_1->getVisibility(); - $this->assertEqual(TRUE, $visibility['request_path']['negate']); - $this->assertEqual('', $visibility['request_path']['pages']); - $this->assertEqual(-5, $test_block_menu_1->weight); - - // Check node block - $test_block_node = $blocks['node']; - $this->assertNotNull($test_block_node); - $this->assertEqual('', $test_block_node->get('region')); - $this->assertEqual('garland', $test_block_node->get('theme')); - $visibility = $test_block_node->getVisibility(); - $this->assertEqual(TRUE, $visibility['request_path']['negate']); - $this->assertEqual('', $visibility['request_path']['pages']); - $this->assertEqual(-4, $test_block_node->weight); - // Check custom blocks $test_block_block = $blocks['block']; $this->assertNotNull($test_block_block); $this->assertEqual('content', $test_block_block->get('region')); - $this->assertEqual('garland', $test_block_block->get('theme')); + $this->assertEqual('bartik', $test_block_block->get('theme')); $visibility = $test_block_block->getVisibility(); $this->assertEqual(FALSE, $visibility['request_path']['negate']); $this->assertEqual('<front>', $visibility['request_path']['pages']); @@ -174,5 +139,23 @@ public function testBlockMigration() { $this->assertEqual(FALSE, $visibility['request_path']['negate']); $this->assertEqual('node', $visibility['request_path']['pages']); $this->assertEqual(-4, $test_block_block_1->weight); + + $test_block_block_2 = $blocks['block_2']; + $this->assertNotNull($test_block_block_2); + $this->assertEqual('right', $test_block_block_2->get('region')); + $this->assertEqual('test_theme', $test_block_block_2->get('theme')); + $visibility = $test_block_block_2->getVisibility(); + $this->assertEqual(TRUE, $visibility['request_path']['negate']); + $this->assertEqual('', $visibility['request_path']['pages']); + $this->assertEqual(-7, $test_block_block_2->weight); + + $test_block_block_3 = $blocks['block_3']; + $this->assertNotNull($test_block_block_3); + $this->assertEqual('left', $test_block_block_3->get('region')); + $this->assertEqual('test_theme', $test_block_block_3->get('theme')); + $visibility = $test_block_block_3->getVisibility(); + $this->assertEqual(TRUE, $visibility['request_path']['negate']); + $this->assertEqual('', $visibility['request_path']['pages']); + $this->assertEqual(-2, $test_block_block_3->weight); } } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index cdcfa3d7998aaadfc6e263883d9c962ced0ea7ef..3fc51b79d69e4f58f7c5aa105eb4de06497e688a 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -105,7 +105,6 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_system_performance', 'd6_system_rss', 'd6_system_site', - 'd6_system_theme', 'd6_taxonomy_settings', 'd6_taxonomy_term', 'd6_taxonomy_vocabulary', @@ -138,6 +137,17 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase { 'd6_vocabulary_field', ); + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $config = \Drupal::config('system.theme'); + $config->set('default', 'bartik'); + $config->set('admin', 'seven'); + $config->save(); + } + /** * {@inheritdoc} */ @@ -186,7 +196,6 @@ protected function getDumps() { $tests_path . '/Drupal6SystemPerformance.php', $tests_path . '/Drupal6SystemRss.php', $tests_path . '/Drupal6SystemSite.php', - $tests_path . '/Drupal6SystemTheme.php', $tests_path . '/Drupal6TaxonomySettings.php', $tests_path . '/Drupal6TaxonomyTerm.php', $tests_path . '/Drupal6TaxonomyVocabulary.php', @@ -260,7 +269,6 @@ protected function getTestClassesList() { __NAMESPACE__ . '\MigrateSystemPerformanceTest', __NAMESPACE__ . '\MigrateSystemRssTest', __NAMESPACE__ . '\MigrateSystemSiteTest', - __NAMESPACE__ . '\MigrateSystemThemeTest', __NAMESPACE__ . '\MigrateTaxonomyConfigsTest', __NAMESPACE__ . '\MigrateTaxonomyTermTest', __NAMESPACE__ . '\MigrateTaxonomyVocabularyTest', diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateSystemThemeTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateSystemThemeTest.php deleted file mode 100644 index bb8dd300cdcead00619e23c6bd7614a2025de59d..0000000000000000000000000000000000000000 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateSystemThemeTest.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\migrate_drupal\Tests\d6\MigrateSystemThemeTest. - */ - -namespace Drupal\migrate_drupal\Tests\d6; - -use Drupal\migrate\MigrateMessage; -use Drupal\migrate\MigrateExecutable; -use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; - -/** - * Upgrade theme variables to system.*.yml. - * - * @group migrate_drupal - */ -class MigrateSystemThemeTest extends MigrateDrupalTestBase { - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $migration = entity_load('migration', 'd6_system_theme'); - $dumps = array( - $this->getDumpDirectory() . '/Drupal6SystemTheme.php', - ); - $this->prepare($migration, $dumps); - $executable = new MigrateExecutable($migration, new MigrateMessage()); - $executable->import(); - } - - /** - * Tests migration of system (theme) variables to system.theme.yml. - */ - public function testSystemTheme() { - $config = \Drupal::config('system.theme'); - $this->assertIdentical($config->get('admin'), '0'); - $this->assertIdentical($config->get('default'), 'garland'); - } - -} diff --git a/core/modules/system/tests/themes/test_theme/test_theme.info.yml b/core/modules/system/tests/themes/test_theme/test_theme.info.yml index d84587538a4834f62c6866b8ffe2abb7a11c5ed6..e35a15d2334951ac04f975bb2c9b2bbacd69b7c4 100644 --- a/core/modules/system/tests/themes/test_theme/test_theme.info.yml +++ b/core/modules/system/tests/themes/test_theme/test_theme.info.yml @@ -17,3 +17,7 @@ stylesheets-remove: - system.module.css settings: theme_test_setting: 'default value' +regions: + content: Content + left: Left + right: Right