From c6890085f97e937d86e1e4b6100c951e10aa913a Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 4 May 2015 17:58:41 -0700 Subject: [PATCH] Issue #2448501 by ultimike, phenaproxima, benjy: Use the migrate cckfield plugin type for the link field --- .../install/migrate.migration.d6_field.yml | 2 - ....migration.d6_field_formatter_settings.yml | 9 --- ...tion.d6_field_instance_widget_settings.yml | 1 - .../migrate_drupal/src/MigrationStorage.php | 59 +++++++++++++------ .../src/Plugin/migrate/cckfield/LinkField.php | 50 ++++++++++++++++ .../src/Plugin/migrate/load/LoadEntity.php | 27 --------- 6 files changed, 92 insertions(+), 56 deletions(-) create mode 100644 core/modules/migrate_drupal/src/Plugin/migrate/cckfield/LinkField.php diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml index 591e3d03dc..e632c8329d 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml @@ -42,8 +42,6 @@ process: text_textarea: text_long email: email_textfield: email - link: - link: link filefield: imagefield_widget: image filefield_widget: file diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml index 20d2364ff0..e7d7cea685 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml @@ -90,15 +90,6 @@ process: spamspan: email_mailto contact: email_mailto plain: basic_string - link: - default: link - plain: link - absolute: link - title_plain: link - url: link - short: link - label: link - separate: link_separate filefield: default: file_default url_plain: file_url_plain diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml index de74309119..40ee7a3756 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml @@ -37,7 +37,6 @@ process: map: text_textfield: text_textfield number: number - link: link_default email_textfield: email_default date_select: datetime_default date_text: datetime_default diff --git a/core/modules/migrate_drupal/src/MigrationStorage.php b/core/modules/migrate_drupal/src/MigrationStorage.php index 18f9f91c20..eb0349bdbd 100644 --- a/core/modules/migrate_drupal/src/MigrationStorage.php +++ b/core/modules/migrate_drupal/src/MigrationStorage.php @@ -8,10 +8,17 @@ namespace Drupal\migrate_drupal; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Uuid\UuidInterface; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\migrate\Plugin\migrate\source\SourcePluginBase; use Drupal\migrate_drupal\Plugin\CckFieldMigrateSourceInterface; use Drupal\migrate\MigrationStorage as BaseMigrationStorage; +use Drupal\migrate_drupal\Plugin\MigratePluginManager; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Storage for migration entities. @@ -30,6 +37,38 @@ class MigrationStorage extends BaseMigrationStorage { */ protected $cckPluginManager; + /** + * Constructs a MigrationStorage object. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service + * The UUID service. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. + * @param \Drupal\migrate_drupal\Plugin\MigratePluginManager + * The cckfield plugin manager. + */ + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, MigratePluginManager $cck_plugin_manager) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); + $this->cckPluginManager = $cck_plugin_manager; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('config.factory'), + $container->get('uuid'), + $container->get('language_manager'), + $container->get('plugin.manager.migrate.cckfield') + ); + } + /** * {@inheritdoc} */ @@ -140,7 +179,6 @@ protected function applyCckFieldProcessors(array $entities) { $method_map = $this->getMigrationPluginMethodMap(); foreach ($entities as $entity_id => $migration) { - // Allow field plugins to process the required migrations. if (isset($method_map[$entity_id])) { $method = $method_map[$entity_id]; @@ -154,7 +192,7 @@ protected function applyCckFieldProcessors(array $entities) { // If this is a CCK bundle migration, allow the cck field plugins to add // any field type processing. $source_plugin = $migration->getSourcePlugin(); - if ($source_plugin instanceof CckFieldMigrateSourceInterface && $source_plugin->getDerivativeId()) { + if ($source_plugin instanceof CckFieldMigrateSourceInterface && strpos($entity_id, SourcePluginBase::DERIVATIVE_SEPARATOR)) { $plugins = $this->getCckFieldPlugins(); foreach ($source_plugin->fieldData() as $field_name => $data) { if (isset($plugins[$data['type']])) { @@ -174,8 +212,8 @@ protected function applyCckFieldProcessors(array $entities) { protected function getCckFieldPlugins() { if (!isset($this->cckFieldPlugins)) { $this->cckFieldPlugins = []; - foreach ($this->getCckPluginManager()->getDefinitions() as $definition) { - $this->cckFieldPlugins[$definition['id']] = $this->getCckPluginManager()->createInstance($definition['id']); + foreach ($this->cckPluginManager->getDefinitions() as $definition) { + $this->cckFieldPlugins[$definition['id']] = $this->cckPluginManager->createInstance($definition['id']); } } return $this->cckFieldPlugins; @@ -196,17 +234,4 @@ protected function getMigrationPluginMethodMap() { ]; } - /** - * Get the cck field plugin manager. - * - * @return \Drupal\migrate_drupal\Plugin\MigratePluginManager - * The loaded plugin manager. - */ - protected function getCckPluginManager() { - if (!isset($this->cckPluginManager)) { - $this->cckPluginManager = \Drupal::service('plugin.manager.migrate.cckfield'); - } - return $this->cckPluginManager; - } - } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/LinkField.php b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/LinkField.php new file mode 100644 index 0000000000..9b70f65fdd --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/LinkField.php @@ -0,0 +1,50 @@ + 'link', + 'plain' => 'link', + 'absolute' => 'link', + 'title_plain' => 'link', + 'url' => 'link', + 'short' => 'link', + 'label' => 'link', + 'separate' => 'link_separate', + ]; + } + + /** + * {@inheritdoc} + */ + public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { + $process = [ + 'plugin' => 'd6_cck_link', + 'source' => [ + $field_name, + $field_name . '_title', + $field_name . '_attributes', + ], + ]; + $migration->mergeProcessOfProperty($field_name, $process); + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php index 570033a68d..181cb447a9 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php @@ -88,9 +88,6 @@ public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = N if ($source_plugin instanceof CckFieldMigrateSourceInterface) { foreach ($source_plugin->fieldData() as $field_name => $data) { switch ($data['type']) { - case 'link': - $this->processLinkField($field_name, $data, $migration); - break; case 'filefield': $this->processFileField($field_name, $data, $migration); break; @@ -176,28 +173,4 @@ protected function processFileField($field_name, $field_data, MigrationInterface $migration->mergeProcessOfProperty($field_name, $process); } - /** - * Manipulate link fields with any per field type processing. - * - * @param string $field_name - * The field we're processing. - * @param array $field_data - * The an array of field type data from the source. - * @param \Drupal\migrate\Entity\MigrationInterface $migration - * The migration entity. - */ - protected function processLinkField($field_name, $field_data, MigrationInterface $migration) { - // Specifically process the link field until core is fixed. - // @see https://www.drupal.org/node/2235457 - $process = [ - 'plugin' => 'd6_cck_link', - 'source' => [ - $field_name, - $field_name . '_title', - $field_name . '_attributes', - ], - ]; - $migration->mergeProcessOfProperty($field_name, $process); - } - } -- GitLab