Problem/Motivation
I use #3506145: Default props values are not used including patterns in twig fixing it from theme point of view with #3506389: Follow default_value defined in YAML schema into twig.
So my ui_suite_dsfr theme deal with default value (taking care of not defined value to use default value) AND defined value.
In a layout builder, i configure a tile to not display icon regarding a boolean field value from an entity. The field return false, but prop is not setted, so default value is applied : TRUE.
The issue here is : i explicitly check FALSE to my entity field, but prop is not defined (because of FALSE). If i check my entity field (TRUE), prop is defined with TRUE value.
in src/Element/ComponentElementBuilder.php :
$data = $source->getValue($prop_type);
if (empty($data) && $prop_type->getPluginId() !== 'attributes') {
// For JSON Schema validator, empty value is not the same as missing
// value, and we want to prevent some of the prop types rules to be
// applied on empty values: string pattern, string format, enum, number
// min/max...
// However, we don't remove empty attributes to avoid an error with
// Drupal\Core\Template\TwigExtension::createAttribute() when themers
// forget to use the default({}) filter.
return $build;
}
$build["#props"][$prop_id] = $data;
}
In my case, $data is FALSE, empty($data) is considered as TRUE, and prop_type plugin id is boolean, not attributes. Which means #props[$prop_id] is never defined.
Issue fork ui_patterns-3510596
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
goz commentedComment #4
pdureau commentedComment #5
pdureau commentedComment #6
just_like_good_vibeschecked with @goz.
for the value injected into a boolean prop, we need to be able to differentiate because those cases :
- NULL value => today we don't inject the prop
- FALSE value => today we don't inject the prop
- TRUE value => today we inject TRUE.
we need to inject FALSE, when an explicit FALSE was injected
Comment #10
just_like_good_vibesready for merge :)
@goz & Christian, would you like to review too ?
Comment #11
just_like_good_vibesComment #12
goz commentedLooks great to me, RTBC
Comment #14
just_like_good_vibes