Commit c6890085 authored by alexpott's avatar alexpott

Issue #2448501 by ultimike, phenaproxima, benjy: Use the migrate cckfield...

Issue #2448501 by ultimike, phenaproxima, benjy: Use the migrate cckfield plugin type for the link field
parent 1d2f9e93
......@@ -42,8 +42,6 @@ process:
text_textarea: text_long
email:
email_textfield: email
link:
link: link
filefield:
imagefield_widget: image
filefield_widget: file
......
......@@ -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
......
......@@ -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
......
......@@ -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;
}
}
<?php
/**
* @file
* Contains Drupal\migrate_drupal\Plugin\migrate\cckfield\LinkField;
*/
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
use Drupal\migrate\Entity\MigrationInterface;
/**
* @PluginID("link")
*/
class LinkField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
// See d6_field_formatter_settings.yml and CckFieldPluginBase
// processFieldFormatter().
return [
'default' => '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);
}
}
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment