diff --git a/core/modules/color/migrations/d7_color.yml b/core/modules/color/migrations/d7_color.yml new file mode 100644 index 0000000000000000000000000000000000000000..9bc7af6c6d76776338bc156c0d936106263538a6 --- /dev/null +++ b/core/modules/color/migrations/d7_color.yml @@ -0,0 +1,54 @@ +id: d7_color +label: Color +migration_tags: + - Drupal 7 + - Configuration +source: + plugin: d7_color + constants: + config_prefix: 'color.theme.' +process: + # Skip if theme not installed on destination. + theme_installed: + plugin: skip_on_empty + source: theme_installed + method: row + element_name: + - + plugin: explode + source: name + delimiter: _ + - + plugin: extract + index: + - 2 + # Skip if the variable name ends in 'screenshot'. + screenshot: + - + plugin: static_map + source: '@element_name' + bypass: true + map: + screenshot: false + - + plugin: skip_on_empty + method: row + # Build the configuration name from the variable name, i.e. + # 'color_themename_element' becomes 'color.theme.themename' + theme_name: + - + plugin: explode + source: name + delimiter: _ + - + plugin: extract + index: + - 1 + configuration_name: + plugin: concat + source: + - constants/config_prefix + - '@theme_name' + value: value +destination: + plugin: color diff --git a/core/modules/color/src/Plugin/migrate/destination/Color.php b/core/modules/color/src/Plugin/migrate/destination/Color.php new file mode 100644 index 0000000000000000000000000000000000000000..4fe62b70517bb976ae1051ae8ee417df5933b11f --- /dev/null +++ b/core/modules/color/src/Plugin/migrate/destination/Color.php @@ -0,0 +1,90 @@ +configFactory = $config_factory; + } + + /** + * {@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') + ); + } + + /** + * {@inheritdoc} + */ + public function import(Row $row, array $old_destination_id_values = []) { + $imported = FALSE; + $value = $row->getDestinationProperty('value'); + if (isset($value)) { + $this->configFactory->getEditable($row->getDestinationProperty('configuration_name')) + ->set($row->getDestinationProperty('element_name'), $row->getDestinationProperty('value')) + ->save(); + $imported = TRUE; + } + return $imported; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['name']['type'] = 'string'; + return $ids; + } + + /** + * {@inheritdoc} + */ + public function fields(MigrationInterface $migration = NULL) { + return []; + } + +} diff --git a/core/modules/color/src/Plugin/migrate/source/d7/Color.php b/core/modules/color/src/Plugin/migrate/source/d7/Color.php new file mode 100644 index 0000000000000000000000000000000000000000..e713f0e27645e1e4e02bc762c33429d15aa7dd9d --- /dev/null +++ b/core/modules/color/src/Plugin/migrate/source/d7/Color.php @@ -0,0 +1,98 @@ +themeHandler = $theme_handler; + } + + /** + * {@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('state'), + $container->get('entity.manager'), + $container->get('theme_handler') + ); + } + + /** + * {@inheritdoc} + */ + public function query() { + // Get color data for all themes. + $query = $this->select('variable', 'v') + ->fields('v', ['name', 'value']) + ->condition('name', 'color_%', 'LIKE'); + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $themes = $this->themeHandler->listInfo(); + $themes_installed = []; + /** @var \Drupal\Core\Extension\Extension $theme */ + foreach ($themes as $theme) { + if ($theme->status) { + $themes_installed[] = $theme->getName(); + } + } + + // The name is of the form 'color_theme_variable'. + $name = explode('_', $row->getSourceProperty('name')); + + // Set theme_installed if this source theme is installed. + if (in_array($name[1], $themes_installed)) { + $row->setSourceProperty('theme_installed', TRUE); + } + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'name' => $this->t('A color variable for a theme.'), + 'value' => $this->t('The value of a color variable.'), + ]; + } + +} diff --git a/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..946d1e38c50664877287e80b8f999897206a05f6 --- /dev/null +++ b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php @@ -0,0 +1,61 @@ +container->get('theme_installer')->install(['bartik']); + $this->executeMigration('d7_color'); + } + + /** + * Tests migration of color's variables to configuration. + */ + public function testMigrateColor() { + // Test Bartik migration. + $config = $this->config('color.theme.bartik'); + $files = [ + 'public://color/bartik-e0e23ad7/logo.png', + 'public://color/bartik-e0e23ad7/colors.css', + ]; + $this->assertSame($files, $config->get('files')); + $this->assertSame('public://color/bartik-e0e23ad7/logo.png', $config->get('logo')); + $palette = [ + 'top' => '#d0d0d0', + 'bottom' => '#c2c4c5', + 'bg' => '#ffffff', + 'sidebar' => '#ffffff', + 'sidebarborders' => '#cccccc', + 'footer' => '#24272c', + 'titleslogan' => '#000000', + 'text' => '#4a4a4a', + 'link' => '#019dbf', + ]; + $this->assertSame($palette, $config->get('palette')); + $this->assertSame(['public://color/bartik-e0e23ad7/colors.css'], $config->get('stylesheets')); + // Test that the screenshot was not migrated. + $this->assertNull($config->get('screenshot')); + + // Test that garland was not migrated. + $this->assertEmpty(\Drupal::config('color.theme.garland')->get()); + } + +} diff --git a/core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php b/core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..cb634a9c63fa9ea289826f960b141cbcd703426a --- /dev/null +++ b/core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php @@ -0,0 +1,129 @@ + 'color_bartik_palette', + 'value' => [ + 'top' => '#cd2d2d', + 'bottom' => '#d64e4e', + 'bg' => '#ffffff', + 'sidebar' => '#f1f4f0', + 'sidebarborders' => '#ededed', + 'footer' => '#1f1d1c', + 'titleslogan' => '#fffeff', + 'text' => '#888888', + 'link' => '#d6121f', + ], + ], + [ + 'name' => 'color_bartik_logo', + 'value' => 'public://color/bartik-e0e23ad7/logo.png', + ], + [ + 'name' => 'color_bartik_stylesheets', + 'value' => ['public://color/bartik-1d249313/colors.css'], + ], + [ + 'name' => 'color_bartik_files', + 'value' => [ + 'public://color/bartik-e0e23ad7/logo.png', + 'public://color/bartik-e0e23ad7/colors.css', + ], + ], + [ + 'name' => 'color_bartik_screenshot', + 'value' => ['public:://color/bartik-b69cfcec/screenshot.png'], + ], + [ + 'name' => 'color_custom_stylesheets', + 'value' => ['public:://color/custom-beadedff/colors.css'], + ], + ]; + + foreach ($tests[0]['database']['variable'] as $key => $expected) { + $tests[0]['database']['variable'][$key]['value'] = serialize($expected['value']); + } + + $tests[0]['database']['system'] = [ + [ + 'name' => 'bartik', + 'type' => 'theme', + 'status' => '1', + ], + [ + 'name' => 'custom', + 'type' => 'theme', + 'status' => '0', + ], + ]; + + // Expected results are the same as the source. + $tests[0]['expected_results'] = [ + [ + 'name' => 'color_bartik_palette', + 'value' => [ + 'top' => '#cd2d2d', + 'bottom' => '#d64e4e', + 'bg' => '#ffffff', + 'sidebar' => '#f1f4f0', + 'sidebarborders' => '#ededed', + 'footer' => '#1f1d1c', + 'titleslogan' => '#fffeff', + 'text' => '#888888', + 'link' => '#d6121f', + ], + ], + [ + 'name' => 'color_bartik_logo', + 'value' => 'public://color/bartik-e0e23ad7/logo.png', + ], + [ + 'name' => 'color_bartik_stylesheets', + 'value' => ['public://color/bartik-1d249313/colors.css'], + ], + [ + 'name' => 'color_bartik_files', + 'value' => [ + 'public://color/bartik-e0e23ad7/logo.png', + 'public://color/bartik-e0e23ad7/colors.css', + ], + ], + [ + 'name' => 'color_bartik_screenshot', + 'value' => ['public:://color/bartik-b69cfcec/screenshot.png'], + ], + [ + 'name' => 'color_custom_stylesheets', + 'value' => ['public:://color/custom-beadedff/colors.css'], + ], + ]; + + return $tests; + } + +} diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 23dd81e977325007577b100c06caeff1a342ab31..6f61f67dcdd5e78444568e4de0827b1735d2d2fd 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -46861,6 +46861,46 @@ 'name' => 'clean_url', 'value' => 's:1:"1";', )) +->values(array( + 'name' => 'color_bartik_files', + 'value' => 'a:2:{i:0;s:39:"public://color/bartik-e0e23ad7/logo.png";i:1;s:41:"public://color/bartik-e0e23ad7/colors.css";}', +)) +->values(array( + 'name' => 'color_bartik_logo', + 'value' => 's:39:"public://color/bartik-e0e23ad7/logo.png";', +)) +->values(array( + 'name' => 'color_bartik_palette', + 'value' => 'a:9:{s:3:"top";s:7:"#d0d0d0";s:6:"bottom";s:7:"#c2c4c5";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#ffffff";s:14:"sidebarborders";s:7:"#cccccc";s:6:"footer";s:7:"#24272c";s:11:"titleslogan";s:7:"#000000";s:4:"text";s:7:"#4a4a4a";s:4:"link";s:7:"#019dbf";}', +)) +->values(array( + 'name' => 'color_bartik_stylesheets', + 'value' => 'a:1:{i:0;s:41:"public://color/bartik-e0e23ad7/colors.css";}', +)) +->values(array( + 'name' => 'color_bartik_screenshot', + 'value' => 's:72:"/var/www/drupal/sites/default/files/color/bartik-b69cfcec/screenshot.png";' +)) +->values(array( + 'name' => 'color_garland_files', + 'value' => 'a:19:{i:0;s:50:"public://color/garland-b69cfcec/menu-collapsed.gif";i:1;s:54:"public://color/garland-b69cfcec/menu-collapsed-rtl.gif";i:2;s:49:"public://color/garland-b69cfcec/menu-expanded.gif";i:3;s:45:"public://color/garland-b69cfcec/menu-leaf.gif";i:4;s:67:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/body.png";i:5;s:69:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-bar.png";i:6;s:75:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-bar-white.png";i:7;s:69:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-tab.png";i:8;s:76:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-navigation.png";i:9;s:78:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-content-left.png";i:10;s:79:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-content-right.png";i:11;s:73:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-content.png";i:12;s:81:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-navigation-item.png";i:13;s:87:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-navigation-item-hover.png";i:14;s:77:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/gradient-inner.png";i:15;s:67:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/logo.png";i:16;s:73:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/screenshot.png";i:17;s:41:"public://color/garland-b69cfcec/style.css";i:18;s:45:"public://color/garland-b69cfcec/style-rtl.css";}', +)) +->values(array( + 'name' => 'color_garland_logo', + 'value' => 's:40:"public://color/garland-b69cfcec/logo.png";' +)) +->values(array( + 'name' => 'color_garland_palette', + 'value' => 'a:5:{s:4:"base";s:7:"#d0cb9a";s:4:"link";s:7:"#917803";s:3:"top";s:7:"#efde01";s:6:"bottom";s:7:"#e6fb2d";s:4:"text";s:7:"#494949";}', +)) +->values(array( + 'name' => 'color_garland_screenshot', + 'value' => 's:73:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/screenshot.png";' +)) +->values(array( + 'name' => 'color_garland_stylesheets', + 'value' => 'a:2:{i:0;s:41:"public://color/garland-b69cfcec/style.css";i:1;s:45:"public://color/garland-b69cfcec/style-rtl.css";}', +)) ->values(array( 'name' => 'comment_anonymous_article', 'value' => 'i:0;', diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php index 0ff29fdf2d279cce41f88ac20144ed549c12461b..dde4d7d92bf7b8d29c2681869f865a848e153cd2 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate; use Drupal\ban\Plugin\migrate\destination\BlockedIP; +use Drupal\color\Plugin\migrate\destination\Color; use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase; use Drupal\migrate\Plugin\migrate\destination\Config; @@ -98,6 +99,7 @@ protected function assertCategories($migrations) { */ protected function getConfigurationClasses() { return [ + Color::class, Config::class, EntityConfigBase::class, ThemeSettings::class, diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php index be048f952503345bd216d1f8a14bb43656b626cf..12b66165aeb57b33648bdb8c390676e35ee903d4 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php @@ -35,6 +35,7 @@ protected function getAvailablePaths() { 'aggregator', 'block', 'book', + 'color', 'comment', 'contact', 'date', @@ -116,7 +117,6 @@ protected function getAvailablePaths() { */ protected function getMissingPaths() { return [ - 'color', 'rdf', 'views', ]; diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php index 27cc4cf271443938986e915bcff16059a8244403..4df392f2c9e17d1734690d74c58b93140a4ab8a1 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php @@ -119,6 +119,7 @@ protected function getAvailablePaths() { 'aggregator', 'block', 'book', + 'color', 'comment', 'contact', 'date', @@ -170,7 +171,6 @@ protected function getAvailablePaths() { */ protected function getMissingPaths() { return [ - 'color', 'rdf', // These modules are in the missing path list because they are installed // on the source site but they are not installed on the destination site.