diff core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php	Wed Nov 29 16:09:58 2017 +0000
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\migrate_drupal\Plugin;
+
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
+use Drupal\migrate\Plugin\MigratePluginManager;
+use Drupal\migrate\Plugin\MigrationInterface;
+
+/**
+ * Plugin manager for migrate field plugins.
+ *
+ * @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
+ * @see \Drupal\migrate\Annotation\MigrateField
+ * @see plugin_api
+ *
+ * @ingroup migration
+ */
+class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
+
+  /**
+   * The default version of core to use for field plugins.
+   *
+   * These plugins were initially only built and used for Drupal 6 fields.
+   * Having been extended for Drupal 7 with a "core" annotation, we fall back to
+   * Drupal 6 where none exists.
+   */
+  const DEFAULT_CORE_VERSION = 6;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
+    $core = static::DEFAULT_CORE_VERSION;
+    if (!empty($configuration['core'])) {
+      $core = $configuration['core'];
+    }
+    elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
+      foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
+        if ($tag == 'Drupal 7') {
+          $core = 7;
+        }
+      }
+    }
+
+    $definitions = $this->getDefinitions();
+    foreach ($definitions as $plugin_id => $definition) {
+      if (in_array($core, $definition['core'])) {
+        if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
+          return $plugin_id;
+        }
+      }
+    }
+    throw new PluginNotFoundException($field_type);
+  }
+
+}