EntityFieldStorageConfig.php 3.93 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\migrate_drupal\Plugin\migrate\destination;

5
use Drupal\Core\Config\ConfigFactoryInterface;
6 7
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
8
use Drupal\Core\Language\LanguageManagerInterface;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
use Drupal\migrate\Plugin\MigrationInterface;
11 12 13
use Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig as BaseEntityFieldStorageConfig;

/**
14
 * Deprecated. Destination with Drupal specific config dependencies.
15 16 17 18
 *
 * @MigrateDestination(
 *   id = "md_entity:field_storage_config"
 * )
19 20 21 22 23 24
 *
 * @deprecated in Drupal 8.2.x and will be removed in Drupal 9.0.x. Use
 *   \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig
 *   instead.
 *
 * @see \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 */
class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig {

  /**
   * The field type plugin manager.
   *
   * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
   */
  protected $fieldTypePluginManager;

  /**
   * Construct a new plugin.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
44
   * @param \Drupal\migrate\Plugin\MigrationInterface $migration
45 46 47 48 49
   *   The migration.
   * @param EntityStorageInterface $storage
   *   The storage for this entity type.
   * @param array $bundles
   *   The list of bundles this entity type has.
50 51 52 53
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
54 55
   * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
   *   The field type plugin manager.
56
   */
57 58 59 60
  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) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $config_factory, $field_type_plugin_manager);
    $this->languageManager = $language_manager;
    $this->configFactory = $config_factory;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    $this->fieldTypePluginManager = $field_type_plugin_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
    $entity_type_id = static::getEntityTypeId($plugin_id);
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
      $container->get('entity.manager')->getStorage($entity_type_id),
      array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)),
76 77
      $container->get('language_manager'),
      $container->get('config.factory'),
78 79 80 81 82 83 84 85 86 87 88
      $container->get('plugin.manager.field.field_type')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    $this->dependencies = parent::calculateDependencies();
    // Add a dependency on the module that provides the field type using the
    // source plugin configuration.
89
    $source_configuration = $this->migration->getSourceConfiguration();
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    if (isset($source_configuration['constants']['type'])) {
      $field_type = $this->fieldTypePluginManager->getDefinition($source_configuration['constants']['type']);
      $this->addDependency('module', $field_type['provider']);
    }
    return $this->dependencies;
  }

  /**
   * {@inheritdoc}
   */
  protected static function getEntityTypeId($plugin_id) {
    return 'field_storage_config';
  }

}