3 namespace Drupal\color\Plugin\migrate\source\d7;
5 use Drupal\Core\Extension\ThemeHandler;
6 use Drupal\migrate\Row;
7 use Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow;
8 use Drupal\Core\Entity\EntityManagerInterface;
9 use Drupal\Core\State\StateInterface;
10 use Drupal\migrate\Plugin\MigrationInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Drupal 7 color source from database.
18 * source_module = "color"
21 class Color extends VariableMultiRow {
26 * @var \Drupal\Core\Extension\ThemeHandler
28 protected $themeHandler;
33 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ThemeHandler $theme_handler) {
34 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
35 $this->themeHandler = $theme_handler;
41 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
47 $container->get('state'),
48 $container->get('entity.manager'),
49 $container->get('theme_handler')
56 public function query() {
57 // Get color data for all themes.
58 $query = $this->select('variable', 'v')
59 ->fields('v', ['name', 'value'])
60 ->condition('name', 'color_%', 'LIKE');
67 public function prepareRow(Row $row) {
68 $themes = $this->themeHandler->listInfo();
69 $themes_installed = [];
70 /** @var \Drupal\Core\Extension\Extension $theme */
71 foreach ($themes as $theme) {
73 $themes_installed[] = $theme->getName();
77 // The name is of the form 'color_theme_variable'.
78 $name = explode('_', $row->getSourceProperty('name'));
80 // Set theme_installed if this source theme is installed.
81 if (in_array($name[1], $themes_installed)) {
82 $row->setSourceProperty('theme_installed', TRUE);
85 return parent::prepareRow($row);
91 public function fields() {
93 'name' => $this->t('A color variable for a theme.'),
94 'value' => $this->t('The value of a color variable.'),