Problem/Motivation
We need to be able to alter FieldGroup labels on render (in Displays) on a per-fieldgroup usage basis.
Use case
We use FieldGroups in Paragraphs to provide is with Teacher-only hints and tips within out educational site and we do this via Paragraphs that are only visible to teachers and not to students.
Sometimes these Paragraphs are 'Hints', other time they are 'Recommended homework' etc. so we need to alter the labels accordingly. We have added a field (label_replacement) for this purpose.
It feel to us that if the label could use token-replacement then that would sort everything very nicely because then we could simply reconfigure the FieldGroup to use the token of the associated field.

However, if that is not possible to provide easily as a new feature or it is not considered to be a good idea to try to use tokens for this then could anyone please guide us as the custom code required (a hook_alter of some kind) to help in the meantime as we can't seem to identify the right one to use.
Many thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3499016 after.png | 171.08 KB | csakiistvan |
| #17 | 3499016 before.png | 149.36 KB | csakiistvan |
| field_group_dynamic_label_requirement.png | 47.24 KB | sirclickalot |
Issue fork field_group-3499016
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:
Comments
Comment #8
super_romeo commentedComment #9
sirclickalot@super_romeo,
Please forgive my ignorance but this mean that the proposed solution will be in 4.x too if and when it passes muster?
I am now on 4.x anyway as we noted that there will be no further commits to 8.x.
Happy to test it out but how should I best go about that given that we have moved on to 4.x ?
Thank you
Comment #10
super_romeo commented@sirclickalot I'd like to upgrade to version 4 too, but the simple_multistep model uses version 3 (https://www.drupal.org/project/simple_multistep/issues/3507839). So I am forced to use version 3.
Comment #12
super_romeo commentedComment #13
sirclickalotHi @super_romeo,
I can confirm that applying the patch from commit: 78295998 work very nicely indeed, I am now able to use a token instead of having to use the additional module Field Group Label.
Comment #14
sirclickalotHi,
Any mileage in getting this in place on a release so that we can remove the reliance on the Field Group Label module.
The patch in https://git.drupalcode.org/project/field_group/-/merge_requests/115#note... works seamlessly as far as I can see.
Thanks
Comment #15
csakiistvanComment #16
csakiistvanEnvironment
Prerequisites
Title token: [node:title].Steps
use_tokens) setting to the Details formatter and replace tokens in the group label at render time when it is enabled and the Token module is available.ddev drush crExpected results
Actual results
Before the fix there is no way to use tokens in a field group label: the label renders literally, e.g. the Details group title showed
Title token: [node:title]. After the fix, with the new Replace tokens in label setting enabled, the same group renders its title asTitle token: Tabs repro node(the[node:title]token replaced with the node title). The setting is only offered when the Token module is present and is off by default, so existing displays are unaffected.Testing produced with the assistance of an LLM.
Comment #17
csakiistvanComment #18
csakiistvan