4fe62b70517bb976ae1051ae8ee417df5933b11f
[yaffs-website] / web / core / modules / color / src / Plugin / migrate / destination / Color.php
1 <?php
2
3 namespace Drupal\color\Plugin\migrate\destination;
4
5 use Symfony\Component\DependencyInjection\ContainerInterface;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\Core\Config\ConfigFactoryInterface;
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate\Row;
10 use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
11
12 /**
13  * Persist color data to the config system.
14  *
15  * @MigrateDestination(
16  *   id = "color"
17  * )
18  */
19 class Color extends DestinationBase implements ContainerFactoryPluginInterface {
20
21   /**
22    * The configuration factory.
23    *
24    * @var \Drupal\Core\Config\ConfigFactoryInterface
25    */
26   protected $configFactory;
27
28   /**
29    * Constructs a Color object.
30    *
31    * @param array $configuration
32    *   Plugin configuration.
33    * @param string $plugin_id
34    *   The plugin ID.
35    * @param mixed $plugin_definition
36    *   The plugin definition.
37    * @param \Drupal\migrate\Plugin\MigrationInterface $migration
38    *   The current migration.
39    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
40    *   The configuration factory.
41    */
42   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ConfigFactoryInterface $config_factory) {
43     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
44     $this->configFactory = $config_factory;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
51     return new static(
52       $configuration,
53       $plugin_id,
54       $plugin_definition,
55       $migration,
56       $container->get('config.factory')
57     );
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function import(Row $row, array $old_destination_id_values = []) {
64     $imported = FALSE;
65     $value = $row->getDestinationProperty('value');
66     if (isset($value)) {
67       $this->configFactory->getEditable($row->getDestinationProperty('configuration_name'))
68         ->set($row->getDestinationProperty('element_name'), $row->getDestinationProperty('value'))
69         ->save();
70       $imported = TRUE;
71     }
72     return $imported;
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function getIds() {
79     $ids['name']['type'] = 'string';
80     return $ids;
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function fields(MigrationInterface $migration = NULL) {
87     return [];
88   }
89
90 }