summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-08-29 07:42:08 -0500
committerAlex Pott2016-08-29 07:42:17 -0500
commit387695762a224fd9da687e3806a15629ca119703 (patch)
tree6887b62e56593ab27423bd6a0c6a7d08d9398af1
parent5e92fad91f149a5e78b0d2bf30748371ad62eb53 (diff)
Issue #2787639 by hussainweb: MigrateCckFieldPluginManager mixes up its behaviour for creating and loading definitions
(cherry picked from commit cea3af0f9441266a5490b8d754435a4488a3eb62)
-rw-r--r--core/modules/field/src/Plugin/migrate/process/FieldType.php3
-rw-r--r--core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php19
-rw-r--r--core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php12
-rw-r--r--core/modules/migrate_drupal/tests/src/Kernel/MigrateCckFieldPluginManagerTest.php23
-rw-r--r--core/modules/node/src/Plugin/migrate/D6NodeDeriver.php8
-rw-r--r--core/modules/node/src/Plugin/migrate/D7NodeDeriver.php8
6 files changed, 50 insertions, 23 deletions
diff --git a/core/modules/field/src/Plugin/migrate/process/FieldType.php b/core/modules/field/src/Plugin/migrate/process/FieldType.php
index 1296940..ad070d0 100644
--- a/core/modules/field/src/Plugin/migrate/process/FieldType.php
+++ b/core/modules/field/src/Plugin/migrate/process/FieldType.php
@@ -72,7 +72,8 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
$field_type = is_array($value) ? $value[0] : $value;
try {
- return $this->cckPluginManager->createInstance($field_type, [], $this->migration)->getFieldType($row);
+ $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
+ return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
}
catch (PluginNotFoundException $e) {
return parent::transform($value, $migrate_executable, $row, $destination_property);
diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php
index 44151cc..7920040 100644
--- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php
+++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php
@@ -27,9 +27,22 @@ class MigrateCckFieldPluginManager extends MigratePluginManager {
const DEFAULT_CORE_VERSION = 6;
/**
- * {@inheritdoc}
+ * Get the plugin ID from the field type.
+ *
+ * @param string $field_type
+ * The field type being migrated.
+ * @param array $configuration
+ * (optioanl) An array of configuration relevant to the plugin instance.
+ * @param \Drupal\migrate\Plugin\MigrationInterface|null $migration
+ * (optional) The current migration instance.
+ *
+ * @return string
+ * The ID of the plugin for the field_type if available.
+ *
+ * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
+ * If the plugin cannot be determined, such as if the field type is invalid.
*/
- public function createInstance($field_type, array $configuration = array(), MigrationInterface $migration = NULL) {
+ public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
$core = static::DEFAULT_CORE_VERSION;
if (!empty($configuration['core'])) {
$core = $configuration['core'];
@@ -45,7 +58,7 @@ class MigrateCckFieldPluginManager extends MigratePluginManager {
foreach ($this->getDefinitions() as $plugin_id => $definition) {
if (in_array($core, $definition['core'])) {
if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
- return parent::createInstance($plugin_id, $configuration, $migration);
+ return $plugin_id;
}
}
}
diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php b/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php
index bffba2c..4042ecd 100644
--- a/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php
+++ b/core/modules/migrate_drupal/src/Plugin/migrate/CckMigration.php
@@ -2,6 +2,7 @@
namespace Drupal\migrate_drupal\Plugin\migrate;
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrateDestinationPluginManager;
@@ -106,12 +107,19 @@ class CckMigration extends Migration implements ContainerFactoryPluginInterface
}
foreach ($source_plugin as $row) {
$field_type = $row->getSourceProperty('type');
- if (!isset($this->processedFieldTypes[$field_type]) && $this->cckPluginManager->hasDefinition($field_type)) {
+ try {
+ $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this);
+ }
+ catch (PluginNotFoundException $ex) {
+ continue;
+ }
+
+ if (!isset($this->processedFieldTypes[$field_type])) {
$this->processedFieldTypes[$field_type] = TRUE;
// Allow the cckfield plugin to alter the migration as necessary so
// that it knows how to handle fields of this type.
if (!isset($this->cckPluginCache[$field_type])) {
- $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this);
+ $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, [], $this);
}
call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this);
}
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/MigrateCckFieldPluginManagerTest.php b/core/modules/migrate_drupal/tests/src/Kernel/MigrateCckFieldPluginManagerTest.php
index 8cea74c..1754cfe 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/MigrateCckFieldPluginManagerTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/MigrateCckFieldPluginManagerTest.php
@@ -22,32 +22,33 @@ class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
public function testPluginSelection() {
$plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
- $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d6\\FileField', get_class($plugin_manager->createInstance('filefield', ['core' => 6])));
+ $plugin_id = $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 6]);
+ $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d6\\FileField', get_class($plugin_manager->createInstance($plugin_id, ['core' => 6])));
try {
- // If this test passes, createInstance will raise a
+ // If this test passes, getPluginIdFromFieldType will raise a
// PluginNotFoundException and we'll never reach fail().
- $plugin_manager->createInstance('filefield', ['core' => 7]);
+ $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 7]);
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
}
catch (PluginNotFoundException $e) {
$this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
}
- $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d7\\ImageField', get_class($plugin_manager->createInstance('image', ['core' => 7])));
- $this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d7\\FileField', get_class($plugin_manager->createInstance('file', ['core' => 7])));
- $this->assertIdentical('Drupal\\migrate_cckfield_plugin_manager_test\\Plugin\\migrate\\cckfield\\D6FileField', get_class($plugin_manager->createInstance('file', ['core' => 6])));
+ $this->assertIdentical('image', $plugin_manager->getPluginIdFromFieldType('image', ['core' => 7]));
+ $this->assertIdentical('file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 7]));
+ $this->assertIdentical('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
- $this->assertIdentical('Drupal\\text\\Plugin\\migrate\\cckfield\\TextField', get_class($plugin_manager->createInstance('text', ['core' => 6])));
- $this->assertIdentical('Drupal\\text\\Plugin\\migrate\\cckfield\\TextField', get_class($plugin_manager->createInstance('text', ['core' => 7])));
+ $this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 6]));
+ $this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 7]));
// Test fallback when no core version is specified.
- $this->assertIdentical('Drupal\\migrate_cckfield_plugin_manager_test\\Plugin\\migrate\\cckfield\\D6NoCoreVersionSpecified', get_class($plugin_manager->createInstance('d6_no_core_version_specified', ['core' => 6])));
+ $this->assertIdentical('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
try {
- // If this test passes, createInstance will raise a
+ // If this test passes, getPluginIdFromFieldType will raise a
// PluginNotFoundException and we'll never reach fail().
- $plugin_manager->createInstance('d6_no_core_version_specified', ['core' => 7]);
+ $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
}
catch (PluginNotFoundException $e) {
diff --git a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php
index f3e1a92..51ce1de 100644
--- a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php
+++ b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php
@@ -3,6 +3,7 @@
namespace Drupal\node\Plugin\migrate;
use Drupal\Component\Plugin\Derivative\DeriverBase;
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
@@ -128,14 +129,15 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
if (isset($fields[$node_type])) {
foreach ($fields[$node_type] as $field_name => $info) {
$field_type = $info['type'];
- if ($this->cckPluginManager->hasDefinition($info['type'])) {
+ try {
+ $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
- $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, ['core' => 6], $migration);
+ $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 6], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
}
- else {
+ catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
}
}
diff --git a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php
index 6efa1c7..2a8c0e4 100644
--- a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php
+++ b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php
@@ -3,6 +3,7 @@
namespace Drupal\node\Plugin\migrate;
use Drupal\Component\Plugin\Derivative\DeriverBase;
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
@@ -98,14 +99,15 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
if (isset($fields[$node_type])) {
foreach ($fields[$node_type] as $field_name => $info) {
$field_type = $info['type'];
- if ($this->cckPluginManager->hasDefinition($field_type)) {
+ try {
+ $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
- $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, ['core' => 7], $migration);
+ $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 7], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
}
- else {
+ catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
}
}