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
Comment #2
fagoplan sounds good!
Comment #3
klausiStarting PR: https://github.com/fago/rules/pull/345
Comment #4
klausiReady for review.
Comment #5
klausimerged.
Comment #7
fagoGreat to this merged - an important step :). While looking through the code I'm wondering about that though:
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.
Comment #8
klausiIn 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.
Comment #9
klausiOk, 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?
Comment #10
fagoyep, looks good!