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