diff -u b/core/modules/color/src/Plugin/migrate/source/d7/Color.php b/core/modules/color/src/Plugin/migrate/source/d7/Color.php --- b/core/modules/color/src/Plugin/migrate/source/d7/Color.php +++ b/core/modules/color/src/Plugin/migrate/source/d7/Color.php @@ -2,7 +2,12 @@ namespace Drupal\color\Plugin\migrate\source\d7; +use Drupal\Core\Extension\ThemeHandler; use Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow; +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\State\StateInterface; +use Drupal\migrate\Plugin\MigrationInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Drupal 7 color source from database. @@ -15,29 +20,60 @@ class Color extends VariableMultiRow { /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandler + */ + protected $themeHandler; + + /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ThemeHandler $theme_handler) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager); + $this->themeHandler = $theme_handler; + } + + 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() { - // Gets active themes. - $themes = $this->select('system', 's') - ->fields('s', ['name', 'type', 'status']) - ->condition('type', 'theme') - ->condition('status', '1') - ->execute() - ->fetchCol('name'); + $themes = $this->themeHandler->listInfo(); + $themes_installed = []; + /** @var \Drupal\Core\Extension\Extension $theme */ + foreach($themes as $theme) { + if ($theme->status) { + $themes_installed[] = $theme->getName(); + } + } - // Gets color data for active themes. + // Get color data for active themes. $query = $this->select('variable', 'v') - ->fields('v', ['name', 'value']) - // Screenshot is not in Drupal 8 configuration, exclude it here. - ->condition('name', 'color_%_screenshot', 'NOT LIKE'); - - $conditions = $query->orConditionGroup(); - foreach ($themes as $theme) { - $active_theme = 'color_' . $theme . '_%'; - $conditions->condition('name', $active_theme, 'LIKE'); + ->fields('v', ['name', 'value']); + + // Get all color variables for each active theme. + $or = $query->orConditionGroup(); + foreach ($themes_installed as $theme) { + $variable_name = 'color_' . $theme . '_%'; + $or->condition('name', $variable_name, 'LIKE'); } - $query->condition($conditions); + // Screenshot is not in Drupal 8 configuration, exclude it here. + $condition = $query->andConditionGroup() + ->condition('name', 'color_%_screenshot', 'NOT LIKE') + ->condition($or); + $query->condition($condition); return $query; } diff -u b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php --- b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php +++ b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php @@ -21,6 +21,8 @@ */ protected function setUp() { parent::setUp(); + // Install the themes used for this test. + $this->container->get('theme_installer')->install(['bartik', 'classy', 'seven', 'stable', 'stark']); $this->executeMigration('d7_color'); } @@ -49,6 +51,9 @@ ]; $this->assertSame($palette, $config->get('palette')); $this->assertSame(['public://color/bartik-e0e23ad7/colors.css'], $config->get('stylesheets')); + + // Test that garland was not migrated. + $this->assertEmpty(\Drupal::config('color.theme.garland')->get()); } } diff -u b/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 --- b/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 @@ -59,12 +59,29 @@ 'name' => 'color_bartik_screenshot', 'value' => ['public:://color/bartik-b69cfcec/screenshot.png'], ], + [ + 'name' => 'color_custom_stylesheets', + 'value' => ['public:://color/custom-beadedff/screenshot.png'], + ], ]; 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', + ], + ]; + $tests[0]['expected_results'] = [ [ 'name' => 'color_bartik_palette', @@ -96,6 +113,7 @@ ], ], ]; + return $tests; }