Same name and namespace in other branches
- 8.9.x core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager
- 9 core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager
Plugin manager for migrate field plugins.
Hierarchy
- class \Drupal\migrate\Plugin\MigratePluginManager extends \Drupal\Core\Plugin\DefaultPluginManager implements MigratePluginManagerInterface
- class \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager implements \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
Expanded class hierarchy of MigrateFieldPluginManager
See also
\Drupal\migrate_drupal\Plugin\MigrateFieldInterface
\Drupal\migrate\Annotation\MigrateField
Related topics
2 files declare their use of MigrateFieldPluginManager
- MigrateFieldPluginManagerTest.php in core/
modules/ migrate_drupal/ tests/ src/ Unit/ MigrateFieldPluginManagerTest.php - MigrationProvidersExistTest.php in core/
modules/ migrate/ tests/ src/ Kernel/ Plugin/ MigrationProvidersExistTest.php
1 string reference to 'MigrateFieldPluginManager'
- migrate_drupal.services.yml in core/
modules/ migrate_drupal/ migrate_drupal.services.yml - core/modules/migrate_drupal/migrate_drupal.services.yml
1 service uses MigrateFieldPluginManager
- plugin.manager.migrate.field in core/
modules/ migrate_drupal/ migrate_drupal.services.yml - Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager
File
- core/
modules/ migrate_drupal/ src/ Plugin/ MigrateFieldPluginManager.php, line 19
Namespace
Drupal\migrate_drupal\PluginView source
class MigrateFieldPluginManager extends MigratePluginManager implements MigrateFieldPluginManagerInterface {
/**
* The default version of core to use for field plugins.
*
* These plugins were initially only built and used for Drupal 6 fields.
* Having been extended for Drupal 7 with a "core" annotation, we fall back to
* Drupal 6 where none exists.
*/
const DEFAULT_CORE_VERSION = 6;
/**
* Get the plugin ID from the field type.
*
* This method determines which field plugin should be used for a given field
* type and Drupal core version, returning the lowest weighted plugin
* supporting the provided core version, and which matches the field type
* either by plugin ID, or in the type_map annotation keys.
*
* @param string $field_type
* The field type being migrated.
* @param array $configuration
* (optional) An array of configuration relevant to the plugin instance.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* (optional) The current migration instance.
*
* @return string
* The ID of the plugin for the field type if available.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* If the plugin cannot be determined, such as if the field type is invalid.
*
* @see \Drupal\migrate_drupal\Annotation\MigrateField
*/
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);
}
/**
* {@inheritdoc}
*/
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);
}
}
}
/**
* {@inheritdoc}
*/
protected function findDefinitions() {
$definitions = parent::findDefinitions();
$this
->sortDefinitions($definitions);
return $definitions;
}
/**
* Sorts a definitions array.
*
* This sorts the definitions array first by the weight column, and then by
* the plugin ID, ensuring a stable, deterministic, and testable ordering of
* plugins.
*
* @param array $definitions
* The definitions array to sort.
*/
protected function sortDefinitions(array &$definitions) {
array_multisort(array_column($definitions, 'weight'), SORT_ASC, SORT_NUMERIC, array_keys($definitions), SORT_ASC, SORT_NATURAL, $definitions);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DiscoveryInterface:: |
public | function | Gets a specific plugin definition. | 2 |
DiscoveryInterface:: |
public | function | Gets the definition of all plugins for this type. | 3 |
DiscoveryInterface:: |
public | function | Indicates if a specific plugin definition exists. | |
MapperInterface:: |
public | function | Gets or creates a plugin instance that satisfies the given options. | 2 |
MigrateFieldPluginManager:: |
constant | The default version of core to use for field plugins. | ||
MigrateFieldPluginManager:: |
protected | function | ||
MigrateFieldPluginManager:: |
public | function | Get the plugin ID from the field type. | |
MigrateFieldPluginManager:: |
public | function | ||
MigrateFieldPluginManager:: |
protected | function | Sorts a definitions array. | |
MigratePluginManager:: |
public | function |
Creates a pre-configured instance of a migration plugin. Overrides MigratePluginManagerInterface:: |
1 |
MigratePluginManager:: |
public | function | Constructs a MigratePluginManager object. | 3 |