Boolean prop with false value is not defined

Created on 3 March 2025, about 1 month ago

Problem/Motivation

I use πŸ› Default props values are not used Active fixing it from theme point of view with πŸ› Follow default_value defined in JSON schema into twig Active .
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.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France goz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024