Skip to content
Snippets Groups Projects

Resolve #3401883 "Schema mapping methods"

Closes #3401883

Merge request reports

Members who can merge are allowed to add commits.

Merged results pipeline passed for 8a6a49d8

Code Quality is loading
Ready to merge by members who can write to the target branch.
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Adam G-H
  • Wim Leers added 1 commit

    added 1 commit

    • 9ffb2195 - Explicit test coverage for [childkey]-based dynamic type selection.

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 7adbee99 - Install module that generates an alternate reality for `condition.plugin.*`,...

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • dd70aa7f - Simplify validateMappingConfigSchemaDefinition().

    Compare with previous version

  • Wim Leers added 2 commits

    added 2 commits

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    Compare with previous version

  • Adam G-H added 2 commits

    added 2 commits

    • 52bc56af - @see the config schema cheat sheet
    • ea695a7b - try to rephrase some stuff

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • fb6096da - Explicit test coverage for not just `[%parent.something]`, but even `[%parent.%parent.something]`.

    Compare with previous version

  • assigned to @alexpott

  • unassigned @alexpott

  • Wim Leers added 1 commit

    added 1 commit

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 5bf832ff - Remove pointless and confusing comment.

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 7e270d1a - Move the validation logic for mapping schema definitions into `Mapping::__construct()`.

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 495be4db - Detect invalid mapping definitions.

    Compare with previous version

  • Wim Leers added 2 commits

    added 2 commits

    • 8da33d34 - Explicit test coverage for detecting invalid mapping definitions.
    • f0e67c60 - Fix bug in `ckeditor5.schema.yml`.

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 761a4726 - Explicit test coverage for the exception for an invalid `requiredKey` flag.

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 34804934 - Update `ConfigSchemaTest` expectations, because it checks the PROCESSED config...

    Compare with previous version

  • Wim Leers added 1 commit

    added 1 commit

    • 7358a16e - Revert premature comment change.

    Compare with previous version

  • Adam G-H
  • assigned to @alexpott

  • Wim Leers added 1 commit

    added 1 commit

    • a4897cc8 - Make helper method non-static.

    Compare with previous version

  • Wim Leers added 2 commits

    added 2 commits

    Compare with previous version

  • Wim Leers resolved all threads

    resolved all threads

  • 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) {
    • Suggested change
      173 foreach (array_keys($possible_type_definitions) as $possible_type_name) {
      173 $valid_keys_per_type = [];
      174 foreach (array_keys($possible_type_definitions) as $possible_type_name) {

      To shut PHPStan up.

    • Please register or sign in to reply
  • 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.

      Suggested change
      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
    • Please register or sign in to reply
  • 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:

      Suggested change
      282 array_keys($this->getTypedDataManager()->getDefinitions()),
      283 fn (string $type) => preg_match("/^$regex$/", $type) === 1
      282 $this->getTypedDataManager()->getDefinitions(),
      283 fn (array $type) => preg_match("/^$regex$/", $type['id']) === 1
    • Please register or sign in to reply
  • 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 of array_filter() and !in_array()? (I know we'd lose the strict type comparison, but I'm not clear it adds any benefit here anyway.)

      Suggested change
      194 fn (array $keys) => array_values(array_filter($keys, fn (string $key) => !in_array($key, $statically_required_keys, TRUE))),
      194 fn (array $keys) => array_values(array_diff($keys, $statically_required_keys)),
      Edited by Adam G-H
    • Please register or sign in to reply
  • Alex Pott added 1 commit

    added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading