If the result value produced by a Token Field is empty the label field must not be rendered, as the core dose with other empty field.
Suppose we have:
1) Node Content Type node.a
a) A field field_a_1 attached to node.a with a Label "A_1"
2) Node Content Type node.b
a) A Filed filed_b_1 that is an entity reference to node.a
b) A Ds Token Filed filed_b_a that want to display the data into field_a_1 of node.a. To do this we use the token [node:field_b_1:entity:field_a_1] with a Label "B_A_1".
Now we have these scenario:
1)
- We have a node of type node.a called "A1" with data "FA1" for field_a_1.
- We have a node of type node.b called "B1" with data "A1" for field_b_1.
- The Display page for node "A1" will display the filed_a_1" with label "A_1" and data "FA1".
- With and without the patch we will have that the Display page for node "B1" will display the field with Label "A_1" the data "FA1".
Here every thing is ok.
2)
- We have a node of type node.a called "A2" with no data for field_a_1.
- We have a node of type node.b called "B2" with data "A2" for field_b_1.
- The Display page for node "A2" will display no filed_a_1: no label "A_1".
- Without the patch on the Display page for node "B2" will be displayed the field Label "A_1" without any data. Not ok!
- With the patch on the Display page for node "B2" will not be displayed the field Label "A_1" because no data.
Comment | File | Size | Author |
---|---|---|---|
#14 | ds-token_field_empty_string_value_as_empty_field-2938358-6.patch | 536 bytes | YazanMajadba |
#4 | interdiff-2938358-1-4.txt | 1.04 KB | manuel.adan |
#4 | ds-token_field_empty_string_value_as_empty_field-2938358-4.patch | 657 bytes | manuel.adan |
empty_fields.patch | 572 bytes | AndreaMaggi |
Issue fork ds-2938358
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:
- 2938358-hide-token-field changes, plain diff MR !7
Comments
Comment #2
AndreaMaggi CreditAttribution: AndreaMaggi commentedComment #3
manuel.adanCategory changed to bug report since empty value fields should not be processed by the field template. For instance, empty fields formatted with the expert template are shown with the prefix, suffix and wrappers surrounding empty string.
Comment #4
manuel.adanPatch from #1 failed to apply. Strict comparison between value and empty string.
Comment #5
sacarney CreditAttribution: sacarney commentedPatch in #4 worked for me.
Comment #6
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedcommitted and pushed, thanks!
Comment #9
mediapal CreditAttribution: mediapal commentedI'm running into the same problem two years later.
drupal 8.9.10 with DS 8.x-3.x-dev
I created a token filed with a token taken from a node field to provide a link:
So even the node field is empty the whole DS token field will be rendert
Comment #11
kreatIL CreditAttribution: kreatIL as a volunteer commentedRunning into the same with the following:
Category: [node:field_article_category]
If field_article_category is empty I would expect the token field not to be rendered at all. Instead, I get this output: "Category:"
Edit: I think the behavior expected here doesn't make much sense. Let there be more than one Token used within a Token field. The programming logic no longer knows when the field should be hidden and when not. So in my use case I simply took a Twig field which allows checking for empty values and react to all possible constellations.
Comment #12
YazanMajadba CreditAttribution: YazanMajadba at Vardot commentedWhen using multiple tokens with space between them in this case the label will be rendered if the value is empty so I did a roll-back the patch
Comment #14
YazanMajadba CreditAttribution: YazanMajadba at Vardot commented