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 ...@@ -2,8 +2,8 @@ id: d6_field
label: Field configuration label: Field configuration
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processField field_plugin_method: processField
source: source:
plugin: d6_field plugin: d6_field
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d6_field_formatter_settings ...@@ -2,8 +2,8 @@ id: d6_field_formatter_settings
label: Field formatter configuration label: Field formatter configuration
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processFieldFormatter field_plugin_method: processFieldFormatter
source: source:
plugin: d6_field_instance_per_view_mode plugin: d6_field_instance_per_view_mode
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d6_field_instance ...@@ -2,8 +2,8 @@ id: d6_field_instance
label: Field instance configuration label: Field instance configuration
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processFieldInstance field_plugin_method: processFieldInstance
source: source:
plugin: d6_field_instance plugin: d6_field_instance
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d6_field_instance_widget_settings ...@@ -2,8 +2,8 @@ id: d6_field_instance_widget_settings
label: Field instance widget configuration label: Field instance widget configuration
migration_tags: migration_tags:
- Drupal 6 - Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processFieldWidget field_plugin_method: processFieldWidget
source: source:
plugin: d6_field_instance_per_form_display plugin: d6_field_instance_per_form_display
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d7_field ...@@ -2,8 +2,8 @@ id: d7_field
label: Field configuration label: Field configuration
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processField field_plugin_method: processField
source: source:
plugin: d7_field plugin: d7_field
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d7_field_formatter_settings ...@@ -2,8 +2,8 @@ id: d7_field_formatter_settings
label: Field formatter configuration label: Field formatter configuration
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processFieldFormatter field_plugin_method: processFieldFormatter
source: source:
plugin: d7_field_instance_per_view_mode plugin: d7_field_instance_per_view_mode
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d7_field_instance ...@@ -2,8 +2,8 @@ id: d7_field_instance
label: Field instance configuration label: Field instance configuration
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processFieldInstance field_plugin_method: processFieldInstance
source: source:
plugin: d7_field_instance plugin: d7_field_instance
constants: constants:
......
...@@ -2,8 +2,8 @@ id: d7_field_instance_widget_settings ...@@ -2,8 +2,8 @@ id: d7_field_instance_widget_settings
label: Field instance widget configuration label: Field instance widget configuration
migration_tags: migration_tags:
- Drupal 7 - Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
cck_plugin_method: processFieldWidget field_plugin_method: processFieldWidget
source: source:
plugin: d7_field_instance_per_form_display plugin: d7_field_instance_per_form_display
constants: constants:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\StaticMap; use Drupal\migrate\Plugin\migrate\process\StaticMap;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface; use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
class FieldType extends StaticMap implements ContainerFactoryPluginInterface { 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. * The migration object.
...@@ -41,14 +41,14 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface { ...@@ -41,14 +41,14 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
* The plugin ID. * The plugin ID.
* @param mixed $plugin_definition * @param mixed $plugin_definition
* The plugin definition. * The plugin definition.
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The cckfield plugin manager. * The field plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration * @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run. * 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); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->cckPluginManager = $cck_plugin_manager; $this->fieldPluginManager = $field_plugin_manager;
$this->migration = $migration; $this->migration = $migration;
} }
...@@ -60,7 +60,7 @@ public static function create(ContainerInterface $container, array $configuratio ...@@ -60,7 +60,7 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration, $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('plugin.manager.migrate.cckfield'), $container->get('plugin.manager.migrate.field'),
$migration $migration
); );
} }
...@@ -72,8 +72,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable ...@@ -72,8 +72,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$field_type = is_array($value) ? $value[0] : $value; $field_type = is_array($value) ? $value[0] : $value;
try { try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration); $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row); return $this->fieldPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
} }
catch (PluginNotFoundException $e) { catch (PluginNotFoundException $e) {
return parent::transform($value, $migrate_executable, $row, $destination_property); return parent::transform($value, $migrate_executable, $row, $destination_property);
......
<?php <?php
namespace Drupal\file\Plugin\migrate\cckfield\d6; namespace Drupal\file\Plugin\migrate\field\d6;
use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/** /**
* @MigrateCckField( * @MigrateField(
* id = "filefield", * id = "filefield",
* core = {6} * core = {6}
* ) * )
*/ */
class FileField extends CckFieldPluginBase { class FileField extends FieldPluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -40,9 +40,9 @@ public function getFieldFormatterMap() { ...@@ -40,9 +40,9 @@ public function getFieldFormatterMap() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [ $process = [
'plugin' => 'd6_cck_file', 'plugin' => 'd6_field_file',
'source' => $field_name, 'source' => $field_name,
]; ];
$migration->mergeProcessOfProperty($field_name, $process); $migration->mergeProcessOfProperty($field_name, $process);
......
<?php <?php
namespace Drupal\file\Plugin\migrate\cckfield\d7; namespace Drupal\file\Plugin\migrate\field\d7;
use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/** /**
* @MigrateCckField( * @MigrateField(
* id = "file", * id = "file",
* core = {7} * core = {7}
* ) * )
*/ */
class FileField extends CckFieldPluginBase { class FileField extends FieldPluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -40,7 +40,7 @@ public function getFieldFormatterMap() { ...@@ -40,7 +40,7 @@ public function getFieldFormatterMap() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [ $process = [
'plugin' => 'iterator', 'plugin' => 'iterator',
'source' => $field_name, 'source' => $field_name,
......
<?php <?php
namespace Drupal\file\Plugin\migrate\cckfield\d7; namespace Drupal\file\Plugin\migrate\field\d7;
use Drupal\migrate\Plugin\MigrationInterface; 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", * id = "image",
* core = {7} * core = {7}
* ) * )
*/ */
class ImageField extends CckFieldPluginBase { class ImageField extends FieldPluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -23,7 +23,7 @@ public function getFieldFormatterMap() { ...@@ -23,7 +23,7 @@ public function getFieldFormatterMap() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [ $process = [
'plugin' => 'iterator', 'plugin' => 'iterator',
'source' => $field_name, 'source' => $field_name,
......
...@@ -2,103 +2,12 @@ ...@@ -2,103 +2,12 @@
namespace Drupal\file\Plugin\migrate\process\d6; 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( * @MigrateProcessPlugin(
* id = "d6_cck_file" * id = "d6_cck_file"
* ) * )
*/ */
class CckFile extends ProcessPluginBase implements ContainerFactoryPluginInterface { class CckFile extends FieldFile { }
/**
* 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 [];
}
}
}
<?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 [];
}
}
}