Mercurial > hg > cmmr2012-drupal-site
diff core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
line wrap: on
line diff
--- a/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php Thu May 09 15:34:47 2019 +0100 @@ -28,7 +28,27 @@ const DEFAULT_CORE_VERSION = 6; /** - * {@inheritdoc} + * 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; @@ -67,4 +87,27 @@ } } + /** + * {@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); + } + }