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.

Issue fork ds-2938358

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AndreaMaggi created an issue. See original summary.

AndreaMaggi’s picture

Issue summary: View changes
manuel.adan’s picture

Version: 8.x-3.1 » 8.x-3.x-dev
Category: Feature request » Bug report
Status: Active » Needs review

Category 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.

manuel.adan’s picture

Patch from #1 failed to apply. Strict comparison between value and empty string.

sacarney’s picture

Patch in #4 worked for me.

swentel’s picture

Status: Needs review » Fixed

committed and pushed, thanks!

  • swentel committed 6492df5 on 8.x-3.x authored by manuel.adan
    Issue #2938358 by manuel.adan, AndreaMaggi: Hide Token Field when the...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mediapal’s picture

I'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:

<div class="jumbotron margin-up">
  <h5>Buy this album - bundle via bandcamp</h5>
  
  <p><a class="btn btn-primary btn-lg" href="[node:field_bandcamp]" role="button">Learn more</a></p>
</div>

So even the node field is empty the whole DS token field will be rendert

kreatIL made their first commit to this issue’s fork.

kreatIL’s picture

Running 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.

YazanMajadba’s picture

When 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

YazanMajadba’s picture