Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When a field is reused, eg by an article and by a basic page, but with different labels, the description in the token tree is not displayed correctly.
Comment | File | Size | Author |
---|---|---|---|
#13 | description_for_reused-2497251-13.patch | 2.66 KB | hussainweb |
| |||
#13 | interdiff-12-13.txt | 873 bytes | hussainweb |
Comments
Comment #1
Maouna CreditAttribution: Maouna at bio.logis Genetic Information Management GmbH commentedComment #5
Maouna CreditAttribution: Maouna at bio.logis Genetic Information Management GmbH commentedComment #6
Dave ReidI'm curious why this doesn't match more of the code in Drupal 7, or if we should cleanup what the Drupal 7 code is doing:
Comment #7
darol100 CreditAttribution: darol100 as a volunteer and commented@Dave Reid,
I think we should clean the D7 version. The patch from #5 looks a lot more cleaner.
Comment #8
BerdirThe function used there is based on field_views_field_label(), which is however in some weird views include file, so I duplicated it.
That's also why the return value is strange, that other function does it in the same way. A cleaner fix might be to change it to return an array that has the labels as value not key and possibly not even include the first one, explicitly declaring it as $additional_labels?
Comment #9
BerdirComment #10
hussainwebHere is a patch which changes the function itself. It also changes the way we call
t()
so that the labels are correctly put in a placeholder tag.Comment #11
BerdirThanks for working on this.
The problem with this is that it is no longer possible for potx to extract translatable strings.
To keep that working, we need two t() calls in an if/else, each must be the complete sentence.
Use \Drupal::service(), one method call less.
I'm not sure but if the instanceof check is really necessary. We soon want to support base fields anyway too, and I very much doubt that given a configurable field, there is a non-configurable field too. that would be... very problematic. So just drop that part.
$field_name vs. $all_labels is somewhat confusing. should be $most_used_label or so.
What if we just return a simple array of labels, sorted by usage? Then we can use the function like this:
$labels = ...
$params['@label'] = array_shift($labels);
if ($labels) {
If there are more labels, do the also known as thing..
}
else {
build the label for a single label.
Comment #12
hussainwebFixing 1, 2, and 4. I wanted to keep 3 separate so as to not break anything. I tested this manually and it works great.
Comment #13
hussainwebNow fixing for point 3 in #11. I tested the token browser and it worked fine. This was a standard install of Drupal 8 with just token installed, cache cleared, and a shared field between two content types.
Comment #14
BerdirThanks, looks good to me.
Not going to make you write tests for this when we have none yet. But it would be great if you could open a follow-up or comment in one of the existing field token related issues (there's a meta too) that we should also add fields to multiple bundles to test this part too.