Problem: the DataFetcher class provides methods to traverse the typed data tree on typed data objects only. There is not way to traverse the tree of data definitions which we need during rules configuration time. Example: We want to validate with our integrity check that the selector "node.field_test.0.value" actually exists when we start form the data definition of an article node.

Solution on the DataFetcher class:
* rename the method ::fetchByPropertyPath() to ::fetchDataByPropertyPath()
* rename the method ::fetchBySubPaths() to ::fetchDataBySubPaths()
* create method fetchDefinitionByPropertyPath(DataDefinitionInterface $typed_data, $property_path, $langcode = NULL))
* create method fetchDefinitionBySubPaths(DataDefinitionInterface $typed_data, array $sub_paths, $langcode = NULL)
* Implement those to methods by traversing DataDefinitionInterfaces.

Comments

klausi created an issue. See original summary.

fago’s picture

plan sounds good!

klausi’s picture

Status: Active » Needs work
klausi’s picture

Status: Needs work » Needs review

Ready for review.

klausi’s picture

Status: Needs review » Fixed

merged.

  • klausi committed c75e42d on 8.x-3.x
    Issue #2650372: Implemented meta data definition fetcher and use that...
fago’s picture

Status: Fixed » Needs work

Great to this merged - an important step :). While looking through the code I'm wondering about that though:

+      elseif ($data_definition instanceof ListDataDefinitionInterface) {
+        $data_definition = $data_definition->getItemDefinition();
+      }

So it seems to dereference the list item even if $name is invalid, e.g. 'list:foo'. Or do I overlook something? The tests seem to lack a testFetchingAtInvalidPosition case also. Thus re-opening for clarifying.

klausi’s picture

Status: Needs work » Active

In a list all property names are forwarded to the item definition of the list. "list.foo" is therefore resolved as "list.0.foo". If the item definition does not have the "foo" property then an exception is thrown.

The exception will probably be "The data selector 'list.foo' cannot be applied because the parent property 'list' is not a list or a complex structure" is the list item is of a primitive type.

Which is a lie, because "list" is a list. The item in list just does not support properties.

We should add more test cases with correct exception messages in such cases.

klausi’s picture

Status: Active » Needs review

Ok, adding a test case with a list of integer: https://github.com/fago/rules/pull/351

I think the exception message is fine when we are aware that property selectors are always forwarded to the item definition of a list: "The data selector 'unknown_property' cannot be applied because the definition of type 'integer' is not a list or a complex structure".

Good enough?

fago’s picture

Status: Needs review » Fixed

yep, looks good!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.