2b33c858b990c9fa698c600d5211d6b9049b268f
[yaffs-website] / web / core / modules / migrate_drupal / src / Plugin / MigrateFieldPluginManager.php
1 <?php
2
3 namespace Drupal\migrate_drupal\Plugin;
4
5 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
6 use Drupal\migrate\Plugin\MigratePluginManager;
7 use Drupal\migrate\Plugin\MigrationInterface;
8
9 /**
10  * Plugin manager for migrate field plugins.
11  *
12  * @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
13  * @see \Drupal\migrate\Annotation\MigrateField
14  * @see plugin_api
15  *
16  * @ingroup migration
17  */
18 class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
19
20   /**
21    * The default version of core to use for field plugins.
22    *
23    * These plugins were initially only built and used for Drupal 6 fields.
24    * Having been extended for Drupal 7 with a "core" annotation, we fall back to
25    * Drupal 6 where none exists.
26    */
27   const DEFAULT_CORE_VERSION = 6;
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
33     $core = static::DEFAULT_CORE_VERSION;
34     if (!empty($configuration['core'])) {
35       $core = $configuration['core'];
36     }
37     elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
38       foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
39         if ($tag == 'Drupal 7') {
40           $core = 7;
41         }
42       }
43     }
44
45     $definitions = $this->getDefinitions();
46     foreach ($definitions as $plugin_id => $definition) {
47       if (in_array($core, $definition['core'])) {
48         if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
49           return $plugin_id;
50         }
51       }
52     }
53     throw new PluginNotFoundException($field_type);
54   }
55
56 }