comparison 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
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
26 * Drupal 6 where none exists. 26 * Drupal 6 where none exists.
27 */ 27 */
28 const DEFAULT_CORE_VERSION = 6; 28 const DEFAULT_CORE_VERSION = 6;
29 29
30 /** 30 /**
31 * {@inheritdoc} 31 * Get the plugin ID from the field type.
32 *
33 * This method determines which field plugin should be used for a given field
34 * type and Drupal core version, returning the lowest weighted plugin
35 * supporting the provided core version, and which matches the field type
36 * either by plugin ID, or in the type_map annotation keys.
37 *
38 * @param string $field_type
39 * The field type being migrated.
40 * @param array $configuration
41 * (optional) An array of configuration relevant to the plugin instance.
42 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
43 * (optional) The current migration instance.
44 *
45 * @return string
46 * The ID of the plugin for the field type if available.
47 *
48 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
49 * If the plugin cannot be determined, such as if the field type is invalid.
50 *
51 * @see \Drupal\migrate_drupal\Annotation\MigrateField
32 */ 52 */
33 public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) { 53 public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) {
34 $core = static::DEFAULT_CORE_VERSION; 54 $core = static::DEFAULT_CORE_VERSION;
35 if (!empty($configuration['core'])) { 55 if (!empty($configuration['core'])) {
36 $core = $configuration['core']; 56 $core = $configuration['core'];
65 throw new BadPluginDefinitionException($plugin_id, $required_property); 85 throw new BadPluginDefinitionException($plugin_id, $required_property);
66 } 86 }
67 } 87 }
68 } 88 }
69 89
90 /**
91 * {@inheritdoc}
92 */
93 protected function findDefinitions() {
94 $definitions = parent::findDefinitions();
95 $this->sortDefinitions($definitions);
96 return $definitions;
97 }
98
99 /**
100 * Sorts a definitions array.
101 *
102 * This sorts the definitions array first by the weight column, and then by
103 * the plugin ID, ensuring a stable, deterministic, and testable ordering of
104 * plugins.
105 *
106 * @param array $definitions
107 * The definitions array to sort.
108 */
109 protected function sortDefinitions(array &$definitions) {
110 array_multisort(array_column($definitions, 'weight'), SORT_ASC, SORT_NUMERIC, array_keys($definitions), SORT_ASC, SORT_NATURAL, $definitions);
111 }
112
70 } 113 }