- Issue created by @Martygraphie
- Status changed to Postponed: needs info
over 1 year ago 1:33pm 22 August 2023 - 🇫🇷France pdureau Paris
Hi Marc-Antoine,
There are 2 distinct topics in your ticket.
Looping on slots (fields) values
As you already know, it is the scope of ✨ Make the Twig loops safer Postponed and we hope it will be fixed upstream, at Twig level.
Testing if a render array is true or false
It is a huge issue in Drupal https://www.drupal.org/project/drupal/issues/953034 🌱 [meta] Themes improperly check renderable arrays when determining visibility Needs work a nightmare for some, but it was not a big deal with UI Patterns usually. However, your issue seems related to this, so let's investigate.
Nothing wrong with the component itself. And nothing wrong with ui_suite_dsfr. It is about the render API.
Let's do some tests with this slot:
{% if description %}<p class="fr-tile__desc">{{ description }}</p>{% endif %}
From https://git.drupalcode.org/project/ui_suite_dsfr/-/blob/1.0.x/templates/...
We expect description to be false.
Test 1: empty array
$variables['description'] = [];
OK: description is false, because in PHP an empty array is false
Test 2: non renderable properties
[ "#cache" => [ "contexts" => [ "user.permissions" ], "tags" => [], "max-age" => -1 ] ]
OK: description is false. i don't know which mechanism do that, but it works OK
Test 3: non renderable properties wrapped in a mapping
Layout Builder is sometimes wrapping the render array in a mapping where the key is the block UUID:
[ "cf124739-3274-41cc-829d-c3465ee4eaa5" => [ "#cache" => [ "contexts" => [ "user.permissions" ], "tags" => [], "max-age" => -1 ] ] ]
KO: description is true. it must be false because there are only non renderable properties here. it seems Drupal is only testing the first level
Marc-Antoine, you tested with Display Suite, so it was another wrapping with another key (the field name, i guess), but it was the same issue. What do you think about this?
- 🇷🇪Réunion Martygraphie Saint-Denis (Réunion)
Hi Pierre,
Yes, I reproduce test 4 (Test 4: non renderable properties wrapped in a mapping) with Display Suite / Display Suite Ui Patterns. But instead of having the uuid generated by Layout Builder, I have the machine name of the field. - Assigned to pdureau
- Status changed to Needs work
over 1 year ago 6:30am 24 August 2023 - Issue was unassigned.
- Status changed to Closed: won't fix
over 1 year ago 2:22pm 26 August 2023 - 🇫🇷France pdureau Paris
This issue is not specific to DSFR and has been moved elsewhere: ✨ Empty field values when not renderable Active