Problem/Motivation
If we are going to be able to use Tokens effectively in Core, we need Core to have tokens for fields on arbitrary entities (including the "implicit" fields like node ID, node title if that hasn't become a real field yet, etc.).
The main use envisioned now would be for PathAuto (see #229568: [polilcy, no patch] Pathauto in core).
Proposed resolution
Take the code in the contrib Token module (or is it in Entity API?) that provides tokens for arbitrary entities and fields, and get it into core.
Remaining tasks
1. Make a patch that puts field/entity tokens into Core.
2. Make sure it has tests.
User interface changes
None.
API changes
Core would provide tokens for arbitrary entities and fields.
Original report by chx
[note: this is obsolete -- we are not using tokens for the theme system now.]
We need field tokens in core for #1499460: [meta] New theme system
Comments
Comment #1
aspilicious commentedAs long there isn't consensus about the linked issue I don't see any reason to hijack the critical task queue with this. When that issue has some kind of approved battleplan this potentially can be a critical task.
Comment #2
dave reidPlease come help work on getting them working in Token module for D7 and then we can make this issue about moving them to D8 core. And I completely disagree with using tokens for the theme system, but that's unrelated.
Please also see:
#1222592: Architecture RFC: Field token architecture
#691078: Field tokens
#1195874: Need to figure out how to create nested tokens from the array token type
#1058912: Prevent recursive tokens
Comment #3
chx commentedDont worry. I have switched to Twig for theme. I will see whether i can find the time for the field tokens.
Comment #4
g089h515r806 commentedI have create a module which name is compound_token that could solve the field tokens issue in drupal 7 base on my idea of compound token. it works very well with core field and custom field module.
At first I think my idea is a little stupid, but now I think it is a good idea.
We do not need to write a lot of code to support field token, just create a simple rule, if user following this rule, then this is a field token.
Comment #5
falcon03 commentedAny chance this feature could be implemented in D8?
Integrating tokens (including field tokens) into an eventual wysiwyg editor for Drupal could be a very, very powerful feature!
Comment #6
dave reidLikely this needs to be re-evaluated with the new Entity property/field API in D8.
Comment #7
jhodgdonI think we need to un-postpone this issue, and try to get it done before Feature Freeze.
Comment #7.0
jhodgdonadd link to pathauto issue
Comment #8
jhodgdonI've created an issue summary for this issue... Maybe someone who knows more about this issue can update it with the actual tasks that would need to be done? In particular, I am not sure whether we should aim to use the current code from Token and/or Entity API contrib modules, or the new Entity property/field API (does it exist? where?) in Drupal 8.
Comment #9
jhodgdonI took a look at the existing 7.x modules:
- The entity_token module from http://drupal.org/project/entity: takes care token types for entities, and of property tokens for entities.
- http://drupal.org/project/token: takes care of field tokens for entities.
So it looks like we would need both of these... I still have no idea about any alternative APIs that could be used to accomplish the same thing?
Comment #10
berdirA 8.x implementation should use the new Entity Field API, which is however not yet implemented by nodes and various field types, so a bit hard to test.
But it should be possible to write token integration with it that covers both fields and properties and should be able to replace most hardcodes tokens that core defines ;) That's not going to happen by Dec 1, though, I think...
Comment #11
jhodgdonTalked to Berdir on IRC... here is the documentation that exists on the Entity Field API:
a) Change notice (sparse currently): http://drupal.org/node/1806650
b) Documentation section on this API: http://drupal.org/node/1794140
c) Sub-page explaining the use of the API somewhat: http://drupal.org/node/1795854
d) The method Drupal\Core\Entity\EntityStorageControllerInterface::getFieldDefinitions() gets you a list of all of the field definitions.
Comment #12
chx commentedI think #1446600: EntityFieldQuery (pseudo-)join support contains valuable examples on who to discover things.
Comment #13
jhodgdonBy the way, I'm pretty sure that field tokens for nodes in the existing d7 Token contrib module are not working right:
#1854412: Document that field tokens need proper display modes setup
Comment #13.0
jhodgdonadd an issue summary with actual proposed tasks etc.
Comment #14
xano#2164635: Automatically expose typed data to token API tries to fix this using a more generic approach.