3 namespace Drupal\migrate_drupal\Plugin\migrate;
5 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\migrate\Exception\RequirementsException;
8 use Drupal\migrate\Plugin\MigrateDestinationPluginManager;
9 use Drupal\migrate\Plugin\MigratePluginManager;
10 use Drupal\migrate\Plugin\Migration;
11 use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
12 use Drupal\migrate\Plugin\RequirementsInterface;
13 use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
14 use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
15 use Symfony\Component\DependencyInjection\ContainerInterface;
18 * Migration plugin class for migrations dealing with field config and values.
20 class FieldMigration extends Migration implements ContainerFactoryPluginInterface {
23 * Defines which configuration option has the migration processing function.
25 * Default method is 'field_plugin_method'. For backwards compatibility,
26 * this constant is overridden in the CckMigration class, in order to
27 * fallback to the old 'cck_plugin_method'.
31 const PLUGIN_METHOD = 'field_plugin_method';
34 * Flag indicating whether the field data has been filled already.
38 protected $init = FALSE;
41 * List of field plugin IDs which have already run.
45 protected $processedFieldTypes = [];
48 * Already-instantiated field plugins, keyed by ID.
50 * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface[]
52 protected $fieldPluginCache;
55 * The field plugin manager.
57 * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
59 protected $fieldPluginManager;
62 * Already-instantiated cckfield plugins, keyed by ID.
64 * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface[]
66 protected $cckPluginCache;
69 * The cckfield plugin manager.
71 * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
73 protected $cckPluginManager;
76 * Constructs a FieldMigration.
78 * @param array $configuration
79 * Plugin configuration.
80 * @param string $plugin_id
82 * @param mixed $plugin_definition
83 * The plugin definition.
84 * @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_manager
85 * The cckfield plugin manager.
86 * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_manager
87 * The field plugin manager.
88 * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
89 * The migration plugin manager.
90 * @param \Drupal\migrate\Plugin\MigratePluginManager $source_plugin_manager
91 * The source migration plugin manager.
92 * @param \Drupal\migrate\Plugin\MigratePluginManager $process_plugin_manager
93 * The process migration plugin manager.
94 * @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager
95 * The destination migration plugin manager.
96 * @param \Drupal\migrate\Plugin\MigratePluginManager $idmap_plugin_manager
97 * The ID map migration plugin manager.
99 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_manager, MigrateFieldPluginManagerInterface $field_manager, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManager $source_plugin_manager, MigratePluginManager $process_plugin_manager, MigrateDestinationPluginManager $destination_plugin_manager, MigratePluginManager $idmap_plugin_manager) {
100 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration_plugin_manager, $source_plugin_manager, $process_plugin_manager, $destination_plugin_manager, $idmap_plugin_manager);
101 $this->cckPluginManager = $cck_manager;
102 $this->fieldPluginManager = $field_manager;
108 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
113 $container->get('plugin.manager.migrate.cckfield'),
114 $container->get('plugin.manager.migrate.field'),
115 $container->get('plugin.manager.migration'),
116 $container->get('plugin.manager.migrate.source'),
117 $container->get('plugin.manager.migrate.process'),
118 $container->get('plugin.manager.migrate.destination'),
119 $container->get('plugin.manager.migrate.id_map')
126 public function getProcess() {
129 $source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin();
130 if ($source_plugin instanceof RequirementsInterface) {
132 $source_plugin->checkRequirements();
134 catch (RequirementsException $e) {
135 // Kill the rest of the method.
139 foreach ($source_plugin as $row) {
140 $field_type = $row->getSourceProperty('type');
143 $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this);
144 $manager = $this->fieldPluginManager;
146 catch (PluginNotFoundException $ex) {
148 $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this);
149 $manager = $this->cckPluginManager;
151 catch (PluginNotFoundException $ex) {
156 if (!isset($this->processedFieldTypes[$field_type]) && $manager->hasDefinition($plugin_id)) {
157 $this->processedFieldTypes[$field_type] = TRUE;
158 // Allow the field plugin to alter the migration as necessary so that
159 // it knows how to handle fields of this type.
160 if (!isset($this->fieldPluginCache[$field_type])) {
161 $this->fieldPluginCache[$field_type] = $manager->createInstance($plugin_id, [], $this);
164 $method = $this->pluginDefinition[static::PLUGIN_METHOD];
165 call_user_func([$this->fieldPluginCache[$field_type], $method], $this);
168 return parent::getProcess();