6d6812187212733c91806329521f4641568ef0c4
[yaffs-website] / web / core / modules / migrate_drupal / src / Plugin / migrate / destination / EntityFieldStorageConfig.php
1 <?php
2
3 namespace Drupal\migrate_drupal\Plugin\migrate\destination;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Field\FieldTypePluginManagerInterface;
8 use Drupal\Core\Language\LanguageManagerInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10 use Drupal\migrate\Plugin\MigrationInterface;
11 use Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig as BaseEntityFieldStorageConfig;
12
13 /**
14  * Deprecated. Destination with Drupal specific config dependencies.
15  *
16  * @MigrateDestination(
17  *   id = "md_entity:field_storage_config"
18  * )
19  *
20  * @deprecated in Drupal 8.2.x and will be removed in Drupal 9.0.x. Use
21  *   \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig
22  *   instead.
23  *
24  * @see \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig
25  */
26 class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig {
27
28   /**
29    * The field type plugin manager.
30    *
31    * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
32    */
33   protected $fieldTypePluginManager;
34
35   /**
36    * Construct a new plugin.
37    *
38    * @param array $configuration
39    *   A configuration array containing information about the plugin instance.
40    * @param string $plugin_id
41    *   The plugin_id for the plugin instance.
42    * @param mixed $plugin_definition
43    *   The plugin implementation definition.
44    * @param \Drupal\migrate\Plugin\MigrationInterface $migration
45    *   The migration.
46    * @param \Drupal\Core\Entity\EntityStorageInterface $storage
47    *   The storage for this entity type.
48    * @param array $bundles
49    *   The list of bundles this entity type has.
50    * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
51    *   The language manager.
52    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
53    *   The configuration factory.
54    * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
55    *   The field type plugin manager.
56    */
57   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, FieldTypePluginManagerInterface $field_type_plugin_manager) {
58     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $config_factory, $field_type_plugin_manager);
59     $this->languageManager = $language_manager;
60     $this->configFactory = $config_factory;
61     $this->fieldTypePluginManager = $field_type_plugin_manager;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
68     $entity_type_id = static::getEntityTypeId($plugin_id);
69     return new static(
70       $configuration,
71       $plugin_id,
72       $plugin_definition,
73       $migration,
74       $container->get('entity.manager')->getStorage($entity_type_id),
75       array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)),
76       $container->get('language_manager'),
77       $container->get('config.factory'),
78       $container->get('plugin.manager.field.field_type')
79     );
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public function calculateDependencies() {
86     $this->dependencies = parent::calculateDependencies();
87     // Add a dependency on the module that provides the field type using the
88     // source plugin configuration.
89     $source_configuration = $this->migration->getSourceConfiguration();
90     if (isset($source_configuration['constants']['type'])) {
91       $field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']);
92       $this->addDependency('module', $field_type['provider']);
93     }
94     return $this->dependencies;
95   }
96
97   /**
98    * {@inheritdoc}
99    */
100   protected static function getEntityTypeId($plugin_id) {
101     return 'field_storage_config';
102   }
103
104 }