Problem/Motivation
Found in #3456008: [later phase] Support matching enum SDC prop shapes against DynamicPropSources, not only generating StaticPropSources
All field item constraints are not found when evaluating prop matches. There are couple problem with this.
-
$complex_data_constraint = array_filter( $field_item->getConstraints(), fn ($c) => $c instanceof ComplexDataConstraint ); if (!empty($complex_data_constraint)) { $field_item_level_constraints_indirect = reset($complex_data_constraint) ->properties[$field_property_name] ?? []; } else { $field_item_level_constraints_indirect = []; }$complex_data_constraintis an array but we only check the first element in the array. I have worked on temporary fix in #3456008 that I will bring in here and it does find more constraints -
$rekey = function (array $constraints) { return array_combine( array_map( fn (Constraint $c): string => get_class($c), $constraints, ), $constraints ); };This is assumes that classes among multiple constraints will be unique but this is not necessarily the case. I haven't checked if we have any cases of this yet though.
-
$field_item_level_constraints_direct = $field_item->getConstraints()[$field_property_name] ?? [];I think the array returned from
getConstraints()is actually always a list so this will never have a key of the property name. In #3456008 I did through an exception if this was to ever happen and it was never hit in our tests.
Steps to reproduce
Proposed resolution
Fix the bugs
Update the test expectations and see if they are reasonable
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork experience_builder-3458580
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
tedbowMarking this as Critical as blocks #3456008: [later phase] Support matching enum SDC prop shapes against DynamicPropSources, not only generating StaticPropSources which is critical
Comment #4
wim leers… because AFAICT Drupal core somehow does not (yet) provide infrastructure for this 🤯
RE: points in issue summary:
assert()that verifies there's an empty intersection, and when we find the first non-empty case, we should match Drupal core's existing behavior. Ideally, Drupal core should provide an API for this …FieldItemBase::getConstraints()also promises this, so I have no idea why I did that. Probably defensive programming? 🤷♂️Comment #5
wim leersIf after this docs + logic improvement, #3456008: [later phase] Support matching enum SDC prop shapes against DynamicPropSources, not only generating StaticPropSources is still blocked, please open a new issue with a failing test case to show what the precise blocker is. This represents a step forward, so I'm going ahead and am merging this.
Comment #7
wim leers