%key in TypeResolver jumps up 2 levels

Created on 20 November 2024, 4 months ago

Problem/Motivation

Steps to reproduce

Proposed resolution

The TypeResolver recurses up schema addresses that can contain wildcards %parent and %key.

It starts off by setting these up with the initial data:

      $data = [
        '%parent' => $data->getParent(),
        '%key' => $data->getName(),
        '%type' => $data->getDataDefinition()->getDataType(),
      ];

Here, %key is set to be the name of the initial data.

At the end of the iteration, if an address part is %parent, the wildcard values need to be updated to go up the tree:

        // Switch replacement values with values from the parent.
        $parent = $data['%parent'];
        $data = $parent->getValue();
        $data['%type'] = $parent->getDataDefinition()->getDataType();
        // The special %parent and %key values now need to point one level up.
        if ($new_parent = $parent->getParent()) {
          $data['%parent'] = $new_parent;
          $data['%key'] = $new_parent->getName();
        }

Walking through this:

> $parent = $data['%parent'];

That's the parent of the first iteration.

> $data = $parent->getValue();

We've now updated $data to be for iteration 2.

> if ($new_parent = $parent->getParent()) {

We get a new parent -- the iteration 2 parent, or the grandparent of the initial data.

> $data['%parent'] = $new_parent;

Our new parent for iteration 2 is this parent.

> $data['%key'] = $new_parent->getName();

The key is here set to the name of the NEW parent -- the grandparent.

At the start of the process, it was set to the name of the initial data.

There is never a point where %key is the name of the initial parent.

Given this schema:

    channels:
      type: sequence
      label: Finder channels
      sequence:
        type: sequence
        label: Finder channel bundles
        sequence:
          type: text
          label: Bundle name
          constraints:
            EntityBundleExists: '...'

and this config value:

channels:
  node:
    - my_bundle

There does not seem to be a way to pass 'node' to the EntityBundleExists constraint, because %key is first 0, then 'channels', but never 'node'.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

configuration system

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    Can you provide config schema examples as to what is currently possible for the two scenarios of '0' and 'channels', and what you think should address 'node'?

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I don't understand the question, sorry.

    It's been a while since I posted this, so I don't remember it much, but from my original post, the problem is this:

    channels:
      node:
        - my_bundle <- %key of this is '0'.
    
    channels:
      node:
        - my_bundle <- %parent.%key of this is 'channels'. Why is it not 'node'?
    
Production build 0.71.5 2024