diff --git a/src/Element/ComponentElementBuilder.php b/src/Element/ComponentElementBuilder.php index e2948b34e57d6a2739782c9dd7d8389d1eca881f..657c456fcc8da0dfd7f1390bc666f4f1673d51b3 100644 --- a/src/Element/ComponentElementBuilder.php +++ b/src/Element/ComponentElementBuilder.php @@ -98,7 +98,7 @@ class ComponentElementBuilder implements TrustedCallbackInterface { } } else { - if (!empty($data) || $prop_type->getPluginId() === 'attributes') { + if (!empty($data) || in_array($prop_type->getPluginId(), ['attributes', 'boolean'])) { // 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, @@ -106,6 +106,8 @@ class ComponentElementBuilder implements TrustedCallbackInterface { // 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. + // We do not remove empty value for boolean neither, because false is + // considered as empty, which is wrong. $build['#props'][$prop_or_slot_id] = $data; } }