Same filename and directory in other branches
- 8.9.x core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php
- 9 core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php
Namespace
Drupal\migrate_drupal\Plugin
File
core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php
View source
<?php
namespace Drupal\migrate_drupal\Plugin;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException;
use Drupal\migrate\Plugin\MigratePluginManager;
use Drupal\migrate\Plugin\MigrationInterface;
class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
const DEFAULT_CORE_VERSION = 6;
public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
$core = static::DEFAULT_CORE_VERSION;
if (!empty($configuration['core'])) {
$core = $configuration['core'];
}
elseif (!empty($migration
->getPluginDefinition()['migration_tags'])) {
foreach ($migration
->getPluginDefinition()['migration_tags'] as $tag) {
if ($tag == 'Drupal 7') {
$core = 7;
}
}
}
$definitions = $this
->getDefinitions();
foreach ($definitions as $plugin_id => $definition) {
if (in_array($core, $definition['core'])) {
if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
return $plugin_id;
}
}
}
throw new PluginNotFoundException($field_type);
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
foreach ([
'core',
'source_module',
'destination_module',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new BadPluginDefinitionException($plugin_id, $required_property);
}
}
}
protected function findDefinitions() {
$definitions = parent::findDefinitions();
$this
->sortDefinitions($definitions);
return $definitions;
}
protected function sortDefinitions(array &$definitions) {
array_multisort(array_column($definitions, 'weight'), SORT_ASC, SORT_NUMERIC, array_keys($definitions), SORT_ASC, SORT_NATURAL, $definitions);
}
}
Classes