3 namespace Drupal\migrate_drupal\Plugin;
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;
11 * Plugin manager for migrate field plugins.
13 * @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
14 * @see \Drupal\migrate\Annotation\MigrateField
19 class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
22 * The default version of core to use for field plugins.
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.
28 const DEFAULT_CORE_VERSION = 6;
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'];
38 elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
39 foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
40 if ($tag == 'Drupal 7') {
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) {
54 throw new PluginNotFoundException($field_type);
60 public function processDefinition(&$definition, $plugin_id) {
61 parent::processDefinition($definition, $plugin_id);
63 foreach (['core', 'source_module', 'destination_module'] as $required_property) {
64 if (empty($definition[$required_property])) {
65 throw new BadPluginDefinitionException($plugin_id, $required_property);