annotate core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php @ 4:a9cd425dd02b

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