Resolve #3401883 "Schema mapping methods"
4 open threads
Closes #3401883
Merge request reports
Activity
added 1 commit
- dd702e1c - `core.data_types.schema.yml`: Mark config dependencies, third party settings...
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
added 1 commit
- 9ffb2195 - Explicit test coverage for [childkey]-based dynamic type selection.
added 1 commit
- 7adbee99 - Install module that generates an alternate reality for `condition.plugin.*`,...
added 1 commit
- dd70aa7f - Simplify validateMappingConfigSchemaDefinition().
added 2 commits
- d65fa2b8 - Per @phenaproxima review: add `@throws` documentation.
- 65ecc069 - Explicit test coverage for [%key]-based dynamic type selection.
added 1 commit
- a9c5f033 - Per @phenaproxima review: improve `getValidKeys()` docs + clarify...
added 2 commits
added 1 commit
- fb6096da - Explicit test coverage for not just `[%parent.something]`, but even `[%parent.%parent.something]`.
- Resolved by Alex Pott
- Resolved by Wim Leers
assigned to @alexpott
unassigned @alexpott
added 1 commit
- Resolved by Wim Leers
- Resolved by Alex Pott
added 1 commit
added 1 commit
- 7e270d1a - Move the validation logic for mapping schema definitions into `Mapping::__construct()`.
added 1 commit
- 761a4726 - Explicit test coverage for the exception for an invalid `requiredKey` flag.
- Resolved by Alex Pott
added 1 commit
- 34804934 - Update `ConfigSchemaTest` expectations, because it checks the PROCESSED config...
- Resolved by Wim Leers
- Resolved by Wim Leers
assigned to @alexpott
added 2 commits
-
871b15f9 - Use equivalent logic using simpler code from @phenaproxima
- 890f74cb - Reduce 3 `$this->getTypedDataManager()` calls to 1.
-
871b15f9 - Use equivalent logic using simpler code from @phenaproxima
157 $possible_types = $this->getPossibleTypes($original_mapping_type); 158 159 // TRICKY: it is tempting to not consider this a dynamic type if only one 160 // concrete type exists. But that would lead to different validation errors 161 // when modules are installed or uninstalled. 162 assert(!empty($possible_types)); 163 164 // Determine all valid keys, across all possible types. 165 $typed_data_manager = $this->getTypedDataManager(); 166 $all_type_definitions = $typed_data_manager->getDefinitions(); 167 $possible_type_definitions = array_intersect_key($all_type_definitions, array_fill_keys($possible_types, TRUE)); 168 // TRICKY: \Drupal\Core\Config\TypedConfigManager::getDefinition() does the 169 // necessary resolving, but TypedConfigManager::getDefinitions() does not! 🤷♂️ 170 // @see \Drupal\Core\Config\TypedConfigManager::getDefinitionWithReplacements() 171 // @see ::getValidKeys() 172 foreach (array_keys($possible_type_definitions) as $possible_type_name) { 152 // Expand the dynamic placeholders to find all mapping types derived from 153 // the original mapping type. To continue the previous example: 154 // - `editor.settings.unicorn` 155 // - `editor.image_upload_settings.*` 156 // - `editor.image_upload_settings.1` 157 $possible_types = $this->getPossibleTypes($original_mapping_type); 158 159 // TRICKY: it is tempting to not consider this a dynamic type if only one 160 // concrete type exists. But that would lead to different validation errors 161 // when modules are installed or uninstalled. 162 assert(!empty($possible_types)); 163 164 // Determine all valid keys, across all possible types. 165 $typed_data_manager = $this->getTypedDataManager(); 166 $all_type_definitions = $typed_data_manager->getDefinitions(); 167 $possible_type_definitions = array_intersect_key($all_type_definitions, array_fill_keys($possible_types, TRUE)); - Comment on lines +166 to +167
Nit: $all_type_definitions is only used once.
166 $all_type_definitions = $typed_data_manager->getDefinitions(); 167 $possible_type_definitions = array_intersect_key($all_type_definitions, array_fill_keys($possible_types, TRUE)); 166 $possible_type_definitions = array_intersect_key($typed_data_manager->getDefinitions(), array_fill_keys($possible_types, TRUE)); Edited by Adam G-H
267 // @see \Drupal\Core\Config\TypedConfigManager::replaceVariable() 268 $matches = []; 269 if (preg_match_all('/(\[[^\]]+\])/', $name, $matches) >= 1) { 270 $name = str_replace($matches[0], '[]', $name); 271 } 272 // Then, replace all `[]` occurrences with `.*` and escape all periods for 273 // use in a regex. So: 274 // `module\.something\.foo_.*` 275 // or 276 // `.*\.third_party\..*` 277 $regex = str_replace(['.', '[]'], ['\.', '.*'], $name); 278 // Now find all possible types: 279 // 1. `module.something.foo_foo`, `module.something.foo_bar`, etc. 280 $possible_types = array_filter( 281 array_keys($this->getTypedDataManager()->getDefinitions()), 282 fn (string $type) => preg_match("/^$regex$/", $type) === 1 - Comment on lines +281 to +282
A small nitpick to improve readability/reduce cognitive load:
178 // ("statically") valid. Not all types have a fallback type. 179 // @see \Drupal\Core\Config\TypedConfigManager::getDefinitionWithReplacements() 180 $fallback_type = $typed_data_manager->findFallback($original_mapping_type); 181 $valid_keys_everywhere = array_intersect_key( 182 $valid_keys_per_type, 183 [$fallback_type => NULL], 184 ); 185 assert(count($valid_keys_everywhere) <= 1); 186 $statically_required_keys = NestedArray::mergeDeepArray($valid_keys_everywhere); 187 188 // Now that statically valid keys are known, determine which valid keys are 189 // only valid in *some* cases: remove the statically valid keys from every 190 // per-type array of valid keys. 191 $valid_keys_some = array_diff_key($valid_keys_per_type, $valid_keys_everywhere); 192 $valid_keys_some_processed = array_map( 193 fn (array $keys) => array_values(array_filter($keys, fn (string $key) => !in_array($key, $statically_required_keys, TRUE))), Nit: For simplicity, could we not use
array_diff()
here instead ofarray_filter()
and!in_array()
? (I know we'd lose the strict type comparison, but I'm not clear it adds any benefit here anyway.)Edited by Adam G-H
Please register or sign in to reply