Active
Project:
Drupal core
Version:
main
Component:
token system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
13 Jun 2012 at 17:18 UTC
Updated:
29 Nov 2024 at 17:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
gaspaio commentedFor both $term and $node (and any other entity with tokens btw) we can :
1) leave the old tokens and do not create new ones for $term->label() and $node->label().
2) leave the old tokens as is and create new ones for $term->label() and $node->label().
3) keep the old token names but replace their values with $term->label() and $node->label().
Here's an initial simple patch that implements (2).
Comment #2
fagoMoving to the token system component, to get it on the radar of token maintainers. How should we handle entity-generic tokens in general? E.g. tokens for entity labels but also entity urls and possible others?
I think it somehow makes sense to have both, the node title and the node label available. As once a module changes the label to point to something else, the title token should still give on the title. Maybe just the overall "node" token without property should point to the label?
Comment #3
dave reidFor now we should handle them individually in each module's token integration. I'm not sold on using the term 'label' in public facing text. Will users really understand that terminology when we never expose the world 'label' in the UI? I think we should still use the terms we use in the UI, but make 'raw' versions available. So something like [node:title-raw] 'The raw title of the node.' with [node:title] 'The title of the node.'.
Comment #4
xanoCan someone explain how this relates to #1764358: Core token values do not use the new entity methods and #2164635: Automatically expose typed data to token API?
Comment #5
dave reidSince those issues were created after this issue, I'm not sure? Although I'm guessing that #1764358: Core token values do not use the new entity methods should supersede this issue.
Comment #6
jhedstromComment #7
areke commentedComment #8
pushpinderchauhan commentedReorlled.
Comment #17
hardik_patel_12 commentedRe-rolled against 9.1.x-dev .
Comment #20
darvanenNeeds patch (or MR) against 9.3.x
Comment #21
suresh prabhu parkala commentedUpdated patch from #17. Tried to fix the custom errors, please review.
Comment #22
darvanenThis is a great example of a simple patch with far-reaching consequences, especially since it introduces new usable tokens to the UI.
This task was created as a space to discuss potential changes to these tokens.
@gaspaio enumerated the possible ways forward in this comment:
And I note with interest this comment from @Berdir:
In my opinion, while standardising to use 'label' within the code makes sense where that code might be extended and used in other ways, but these tokens are specific to Node and Token and already use the correct specific labels for those entities, which is a better user experience for the primary users of tokens: site builders.
I think there's a case to make for using
->label()under the hood (option 3) however I have seen a comment or two expressing concern that this may lead to a breakage if the definition of label is ever changed. I'm not convinced this is a concern but I'm very willing to learn how it might be.If it is decied that this is a good change to make there are a bunch of things that need to happen to support it:
I wouldn't put effort into those until a decision has been reached, so I've set this to Active rather than Needs Work for now.
Comment #23
larowlanI agree that using
$entity->label()under the hood makes sense. We have a unified API for a reason.But we'll need to keep
[node:title]and[term:name]for BC reasonsComment #24
darvanenSorry @larowlan, just to clarify - I take it you mean to use
$entity->labelto replace the existing tokens and not create[node:label]and[term:label]tokens?Comment #25
larowlanSorry, I misunderstood the question.
Is there a use-case for having a generic label token? e.g. allowing something to dynamically use
"[$entity_type_id:label]"If there is, then i see merit in this. If there's not then we're just duplicating existing tokens right?
Comment #26
darvanenHm, if you're inserting tokens in such a way that you can use variables, surely you no longer need tokens?
Perhaps I should try and get this tabled in a UX meeting... though there are about a dozen questions I have for this subsystem's roadmap and while this issue is simple it doesn't seem like the right place to start.
Comment #27
aaronmchaleI can see value in this.
As someone who develops custom Entity Types, it's useful to have the generic
labelbecause the Entity Type might not have atitle(in the traditional sense of a title field), the label might be programmatically generated based on other fields. So having that flexibility in tokens of being able to grab whatever any given Entity Type uses as the label makes sense to me.I would argue to keep them regardless, as in don't deprecate them.
The way I see it is
titleandnameare individual fields, they should be exposed like any other field would be; It's theoretically possible for[node:title]to contain one value (the value that the user inputted into the title field), where[node:label]might have been modified to contain some different value which might be built using a combination of fields, maybe[node:label]outputs something like#[node:id]: [node:title]. This kind of scenario is easily enabled by #2570593: Allow entities to be subclassed using "bundle classes" where a developer could sub-class say the Article content type and override the->label()method to produce something other than the simply the value oftitle.Comment #28
berdirIMHO the only reason to do this issue is to actually do it in a generic way like the issue title proposes, similar to #2920310: [PP-1] Implement revision tokens for content entities, which would then be blocked on the same issue.
That also makes the label vs title method a non-issue because generic code then must use the generic method.
Comment #33
anybodyJust ran into this in Drupal commerce and agree it would still be very helpful to have label available, returning the results from
->label().