Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[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\Exception\BadPluginDefinitionException;
7 use Drupal\migrate\Plugin\MigratePluginManager;
8 use Drupal\migrate\Plugin\MigrationInterface;
9
10 /**
11  * Plugin manager for migrate field plugins.
12  *
13  * @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
14  * @see \Drupal\migrate\Annotation\MigrateField
15  * @see plugin_api
16  *
17  * @ingroup migration
18  */
19 class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
20
21   /**
22    * The default version of core to use for field plugins.
23    *
24    * These plugins were initially only built and used for Drupal 6 fields.
25    * Having been extended for Drupal 7 with a "core" annotation, we fall back to
26    * Drupal 6 where none exists.
27    */
28   const DEFAULT_CORE_VERSION = 6;
29
30   /**
31    * {@inheritdoc}
32    */
33   public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
34     $core = static::DEFAULT_CORE_VERSION;
35     if (!empty($configuration['core'])) {
36       $core = $configuration['core'];
37     }
38     elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
39       foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
40         if ($tag == 'Drupal 7') {
41           $core = 7;
42         }
43       }
44     }
45
46     $definitions = $this->getDefinitions();
47     foreach ($definitions as $plugin_id => $definition) {
48       if (in_array($core, $definition['core'])) {
49         if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
50           return $plugin_id;
51         }
52       }
53     }
54     throw new PluginNotFoundException($field_type);
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function processDefinition(&$definition, $plugin_id) {
61     parent::processDefinition($definition, $plugin_id);
62
63     foreach (['core', 'source_module', 'destination_module'] as $required_property) {
64       if (empty($definition[$required_property])) {
65         throw new BadPluginDefinitionException($plugin_id, $required_property);
66       }
67     }
68   }
69
70 }