Improve handling of "Hide Token Field when the value data is empty"

Created on 9 September 2024, 8 months ago

Problem/Motivation

In 🐛 Hide Token Field when the value data is empty Fixed a check was made to handle an empty value being returned from the token field.

It would be useful if this could be extended so that we can handle situations where the value is not empty - but no tokens were replaced.

Steps to reproduce

  • Add an address field to a content type.
  • Add a token field with [node:field_address:organization], [node:field_address:address_line1], [node:field_address:locality] [node:field_address:postal_code], [node:field_address:country_name]

When the field_address is not populated the token field would be rendered as:

, , , ,

Proposed resolution

  • Add additional configuration option to token fields to hide when replaced text is the same as the original value
  • If this is selected render the token with clear = FALSE to compare to the original value

Remaining tasks

Agree on approach
Confirm wording
Implement

User interface changes

Additional configuration option for token fields

API changes

n/a

Data model changes

Additional configuration for token fields

📌 Task
Status

Active

Version

5.0

Component

Code

Created by

🇳🇿New Zealand ericgsmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ericgsmith
  • Merge request !36#3472954 Check for empty rendered token → (Open) created by ericgsmith
  • 🇳🇿New Zealand ericgsmith

    Added a quick proof of concept to show the idea on 8.x-3.x branch - but I see the 5.x branch is quite different for the token field form - haven't investigated the 5.x branch since we are still on the 3.x branch for the project we need this for.

  • Pipeline finished with Failed
    8 months ago
    Total: 560s
    #277614
  • 🇧🇪Belgium swentel

    You can completely ignore the 5.0.x branch, everything still happens on 8.x-3.x :)

  • Pipeline finished with Success
    8 months ago
    Total: 348s
    #278646
  • Status changed to Needs review 8 months ago
  • 🇳🇿New Zealand ericgsmith

    Thanks @swentel - I should have read the module page first!

    I have tidied up the MR and added tests to demonstrate what I am hoping to achieve here.

  • Pipeline finished with Success
    8 months ago
    Total: 382s
    #278653
  • 🇧🇪Belgium swentel

    Sorry for the delay, but patch looks fine, and with tests, always good!

    However, I wonder, without testing myself though, whether we could change the existing logic: instead of calling replace with 'clear' => TRUE the first time, use FALSE there and then add the logic checking whether it's empty or having the same content. That way, the replace call only happens once. If, and only if, that works, we don't even need the 'hide_if_no_tokens_replaced' option at all.

    Also, looking at the follow up comments in 🐛 Hide Token Field when the value data is empty Fixed - it looks like adding a trim($value) would be useful too to be really sure.

    Thoughts?

Production build 0.71.5 2024