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.

Command icon 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

goz created an issue. See original summary.

goz’s picture

Status: Active » Needs review
pdureau’s picture

Title: Boolean prop with false value is not defined » [2.0.1] Boolean prop with false value is not defined
pdureau’s picture

Title: [2.0.1] Boolean prop with false value is not defined » [2.0.2] Boolean prop with false value is not defined
just_like_good_vibes’s picture

Title: [2.0.2] Boolean prop with false value is not defined » [2.0.4] Improve prop value rendering for booleans
Assigned: Unassigned » just_like_good_vibes
Status: Needs review » Needs work

checked 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

just_like_good_vibes changed the visibility of the branch 3510596-boolean-prop-with to hidden.

just_like_good_vibes changed the visibility of the branch 2.0.x to hidden.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » pdureau
Status: Needs work » Needs review

ready for merge :)

@goz & Christian, would you like to review too ?

just_like_good_vibes’s picture

goz’s picture

Looks great to me, RTBC

just_like_good_vibes’s picture

Assigned: christian.wiedemann » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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