- Issue created by @Grimreaper
- πΊπ¦Ukraine SmovS Lutsk
Hi @grimreaper
I have added a check for a non-empty value according to your proposal.But I'm still confused about this false positive when checking slots.
E.g. I set the caption in the table with wysiwig source with an empty textarea.In this case, the table contains an empty caption tag because wysiwig source creates an array with text format settings.
It would be cleaned by self::cleanRenderArray(), but didn'tI am not sure if it is related to the false positive that you mentioned. Probably I went the wrong way.
- π«π·France Grimreaper France π«π·
Hi @smovs,
The problem occurs for example when using the table component with the views table presenter template.
If you are using a component "manually" or with site building it is ok.
But with a presenter template, like written in the issue summary, you can get an empty string as slot value and in this case the problem occurs.
So, to test you can create a view using the table display (not component display using the table component).
- πΊπ¦Ukraine SmovS Lutsk
Hi @grimreaper
Sorry for the delay.
What I found.
From my point of view, rendering works as expected in general, because:
When we check if$value
is empty and set it['#cache' => []]
, we create a non-empty array. It means we redefine the variable from non-array to array in this case. SeeSlotPropType::normalize
if (!is_array($value)) { return empty($value) ? ['#cache' => []] : ['#plain_text' => (string) $value]; }
In Twig template, when we check
{% if caption %}
is always true because in this case, we pass a non-empty array.I am not fully understanding the purpose of the forced setting
['#cache' => []]
each time.I added screenshots for better understanding
- π«π·France Grimreaper France π«π·
Hi @smovs,
In Twig template, when we check {% if caption %} is always true because in this case, we pass a non-empty array.
Yes, and that's the purpose of this issue, we should be able to keep a simple if statement in Twig and having check as expected. We don't want an empty caption to appear.
we create a non-empty array.
That's what needs to be challenged.
Note: I can't reassign the issue to you.
- πΊπ¦Ukraine SmovS Lutsk
@grimreaper
Thank you for the clarification. I will take a look on this weekend - Assigned to SmovS
- Status changed to Needs work
24 days ago 2:22pm 31 July 2025 - πΊπ¦Ukraine SmovS Lutsk
Hi team!
Please review my changes to fix the issue with false positive when checking empty slots. - π«π·France Grimreaper France π«π·
Thanks @smovs !
Tested on the encountered case of empty caption in views table: OK
@pdureau, should we let Christian or Mikael merge?
- π«π·France just_like_good_vibes PARIS
hello,
sorry trimming here is not appropriate :)
we need to cope with this edge case in a better way. - π«π·France pdureau Paris
i agree there is something to do: a string resolving as a false boolean (so, empty) must become a renderable resolving as a false array (so, empty)
However, we have already stated than SDC validator is sometimes confused by an empty slot: https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/Element/...
So maybe it is a 2 steps fix: first fix at SDC level, then do something like that (naive, not tested, proposal):
if (is_string($value)) { return empty($value) ? [] : ['#markup' => $value]; }
- πΊπ¦Ukraine SmovS Lutsk
Hi all!
@pdureau
Your approach in #19 has an edge case with the string"0"
. We need additional checking for it.
empty("0")
returnTRUE
See here stackoverflow
- πΊπ¦Ukraine SmovS Lutsk
Hi team!
I've updated the condition for the string normalization to replace trimming with empty().Please review