Commit 24f816a1 authored by alexpott's avatar alexpott

Issue #2683435 by hussainweb, mikeryan, quietone, alexpott, michael_wojcik,...

Issue #2683435 by hussainweb, mikeryan, quietone, alexpott, michael_wojcik, phenaproxima, benjy: Consider renaming Migrate's cckfield plugins
parent 6489345f
......@@ -2,8 +2,8 @@ id: d6_field
label: Field configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processField
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processField
source:
plugin: d6_field
constants:
......
......@@ -2,8 +2,8 @@ id: d6_field_formatter_settings
label: Field formatter configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldFormatter
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldFormatter
source:
plugin: d6_field_instance_per_view_mode
constants:
......
......@@ -2,8 +2,8 @@ id: d6_field_instance
label: Field instance configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldInstance
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldInstance
source:
plugin: d6_field_instance
constants:
......
......@@ -2,8 +2,8 @@ id: d6_field_instance_widget_settings
label: Field instance widget configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldWidget
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldWidget
source:
plugin: d6_field_instance_per_form_display
constants:
......
......@@ -2,8 +2,8 @@ id: d7_field
label: Field configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processField
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processField
source:
plugin: d7_field
constants:
......
......@@ -2,8 +2,8 @@ id: d7_field_formatter_settings
label: Field formatter configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldFormatter
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldFormatter
source:
plugin: d7_field_instance_per_view_mode
constants:
......
......@@ -2,8 +2,8 @@ id: d7_field_instance
label: Field instance configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldInstance
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldInstance
source:
plugin: d7_field_instance
constants:
......
......@@ -2,8 +2,8 @@ id: d7_field_instance_widget_settings
label: Field instance widget configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldWidget
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldWidget
source:
plugin: d7_field_instance_per_form_display
constants:
......
......@@ -8,7 +8,7 @@
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\StaticMap;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -19,11 +19,11 @@
class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
/**
* The cckfield plugin manager.
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $cckPluginManager;
protected $fieldPluginManager;
/**
* The migration object.
......@@ -41,14 +41,14 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager
* The cckfield plugin manager.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrationInterface $migration = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->cckPluginManager = $cck_plugin_manager;
$this->fieldPluginManager = $field_plugin_manager;
$this->migration = $migration;
}
......@@ -60,7 +60,7 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.migrate.cckfield'),
$container->get('plugin.manager.migrate.field'),
$migration
);
}
......@@ -72,8 +72,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$field_type = is_array($value) ? $value[0] : $value;
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
return $this->fieldPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
}
catch (PluginNotFoundException $e) {
return parent::transform($value, $migrate_executable, $row, $destination_property);
......
<?php
namespace Drupal\file\Plugin\migrate\cckfield\d6;
namespace Drupal\file\Plugin\migrate\field\d6;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateCckField(
* @MigrateField(
* id = "filefield",
* core = {6}
* )
*/
class FileField extends CckFieldPluginBase {
class FileField extends FieldPluginBase {
/**
* {@inheritdoc}
......@@ -40,9 +40,9 @@ public function getFieldFormatterMap() {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'd6_cck_file',
'plugin' => 'd6_field_file',
'source' => $field_name,
];
$migration->mergeProcessOfProperty($field_name, $process);
......
<?php
namespace Drupal\file\Plugin\migrate\cckfield\d7;
namespace Drupal\file\Plugin\migrate\field\d7;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateCckField(
* @MigrateField(
* id = "file",
* core = {7}
* )
*/
class FileField extends CckFieldPluginBase {
class FileField extends FieldPluginBase {
/**
* {@inheritdoc}
......@@ -40,7 +40,7 @@ public function getFieldFormatterMap() {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'iterator',
'source' => $field_name,
......
<?php
namespace Drupal\file\Plugin\migrate\cckfield\d7;
namespace Drupal\file\Plugin\migrate\field\d7;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateCckField(
* @MigrateField(
* id = "image",
* core = {7}
* )
*/
class ImageField extends CckFieldPluginBase {
class ImageField extends FieldPluginBase {
/**
* {@inheritdoc}
......@@ -23,7 +23,7 @@ public function getFieldFormatterMap() {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'iterator',
'source' => $field_name,
......
......@@ -2,103 +2,12 @@
namespace Drupal\file\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @deprecated in Drupal 8.2.x and will be removed before Drupal 9.0.x. Use the
* d6_field_file plugin instead.
*
* @MigrateProcessPlugin(
* id = "d6_cck_file"
* )
*/
class CckFile extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migration process plugin, configured for lookups in d6_file.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*/
protected $migrationPlugin;
/**
* Constructs a CckFile plugin instance.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The current migration.
* @param \Drupal\migrate\Plugin\MigrateProcessInterface $migration_plugin
* An instance of the 'migration' process plugin.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->migrationPlugin = $migration_plugin;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
// Configure the migration process plugin to look up migrated IDs from
// the d6_file migration.
$migration_plugin_configuration = [
'source' => ['fid'],
'migration' => 'd6_file',
];
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration,
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration)
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$options = unserialize($value['data']);
// Try to look up the ID of the migrated file. If one cannot be found, it
// means the file referenced by the current field item did not migrate for
// some reason -- file migration is notoriously brittle -- and we do NOT
// want to send invalid file references into the field system (it causes
// fatals), so return an empty item instead.
try {
$fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property);
}
// If the migration plugin completely fails its lookup process, it will
// throw a MigrateSkipRowException. It shouldn't, but that is being dealt
// with at https://www.drupal.org/node/2487568. Until that lands, return
// an empty item.
catch (MigrateSkipRowException $e) {
return [];
}
if ($fid) {
return [
'target_id' => $fid,
'display' => $value['list'],
'description' => isset($options['description']) ? $options['description'] : '',
'alt' => isset($options['alt']) ? $options['alt'] : '',
'title' => isset($options['title']) ? $options['title'] : '',
];
}
else {
return [];
}
}
}
class CckFile extends FieldFile { }
<?php
namespace Drupal\file\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @MigrateProcessPlugin(
* id = "d6_field_file"
* )
*/
class FieldFile extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migration process plugin, configured for lookups in d6_file.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*/
protected $migrationPlugin;
/**
* Constructs a File plugin instance.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The current migration.
* @param \Drupal\migrate\Plugin\MigrateProcessInterface $migration_plugin
* An instance of the 'migration' process plugin.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->migrationPlugin = $migration_plugin;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
// Configure the migration process plugin to look up migrated IDs from
// the d6_file migration.
$migration_plugin_configuration = [
'source' => ['fid'],
'migration' => 'd6_file',
];
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration,
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration)
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$options = unserialize($value['data']);
// Try to look up the ID of the migrated file. If one cannot be found, it
// means the file referenced by the current field item did not migrate for
// some reason -- file migration is notoriously brittle -- and we do NOT
// want to send invalid file references into the field system (it causes
// fatals), so return an empty item instead.
try {
$fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property);
}
// If the migration plugin completely fails its lookup process, it will
// throw a MigrateSkipRowException. It shouldn't, but that is being dealt
// with at https://www.drupal.org/node/2487568. Until that lands, return
// an empty item.
catch (MigrateSkipRowException $e) {
return [];
}
if ($fid) {
return [
'target_id' => $fid,
'display' => $value['list'],
'description' => isset($options['description']) ? $options['description'] : '',
'alt' => isset($options['alt']) ? $options['alt'] : '',
'title' => isset($options['title']) ? $options['title'] : '',
];
}
else {
return [];
}
}
}
......@@ -2,7 +2,7 @@
namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
use Drupal\file\Plugin\migrate\process\d6\CckFile;
use Drupal\file\Plugin\migrate\process\d6\FieldFile;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
......@@ -12,7 +12,7 @@
/**
* @group file
*/
class CckFileTest extends UnitTestCase {
class FieldFileTest extends UnitTestCase {
/**
* Tests that alt and title attributes are included in transformed values.
......@@ -25,7 +25,7 @@ public function testTransformAltTitle() {
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$migration_plugin->transform(1, $executable, $row, 'foo')->willReturn(1);
$plugin = new CckFile(array(), 'd6_cck_file', array(), $migration, $migration_plugin->reveal());
$plugin = new FieldFile(array(), 'd6_field_file', array(), $migration, $migration_plugin->reveal());
$options = array(
'alt' => 'Foobaz',
......
<?php
namespace Drupal\link\Plugin\migrate\cckfield;
namespace Drupal\link\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateCckField(
* @MigrateField(
* id = "link",
* core = {6},
* type_map = {
......@@ -14,13 +14,13 @@
* }
* )
*/
class LinkField extends CckFieldPluginBase {
class LinkField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
// See d6_field_formatter_settings.yml and CckFieldPluginBase
// See d6_field_formatter_settings.yml and FieldPluginBase
// processFieldFormatter().
return [
'default' => 'link',
......@@ -37,9 +37,9 @@ public function getFieldFormatterMap() {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'd6_cck_link',
'plugin' => 'd6_field_link',
'source' => $field_name,
];
$migration->mergeProcessOfProperty($field_name, $process);
......
<?php
namespace Drupal\link\Plugin\migrate\cckfield\d7;
namespace Drupal\link\Plugin\migrate\field\d7;
use Drupal\link\Plugin\migrate\cckfield\LinkField as D6LinkField;
use Drupal\link\Plugin\migrate\field\LinkField as D6LinkField;
/**
* @MigrateCckField(
* @MigrateField(
* id = "link_field",
* core = {7},
* type_map = {
......
......@@ -2,85 +2,12 @@
namespace Drupal\link\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @deprecated in Drupal 8.2.x and will be removed before Drupal 9.0.x. Use the
* d6_field_link plugin instead.
*
* @MigrateProcessPlugin(
* id = "d6_cck_link"
* )
*/
class CckLink extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
}
/**
* {@inheritdoc}