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

aspilicious’s picture

Priority: Critical » Normal

As 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.

dave reid’s picture

Status: Active » Postponed

Please 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

chx’s picture

Dont worry. I have switched to Twig for theme. I will see whether i can find the time for the field tokens.

g089h515r806’s picture

I 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.

falcon03’s picture

Any 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!

dave reid’s picture

Likely this needs to be re-evaluated with the new Entity property/field API in D8.

jhodgdon’s picture

Status: Postponed » Active

I think we need to un-postpone this issue, and try to get it done before Feature Freeze.

jhodgdon’s picture

Issue summary: View changes

add link to pathauto issue

jhodgdon’s picture

I'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.

jhodgdon’s picture

I 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?

berdir’s picture

A 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...

jhodgdon’s picture

Talked 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.

chx’s picture

I think #1446600: EntityFieldQuery (pseudo-)join support contains valuable examples on who to discover things.

jhodgdon’s picture

By 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

jhodgdon’s picture

Issue summary: View changes

add an issue summary with actual proposed tasks etc.

xano’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

#2164635: Automatically expose typed data to token API tries to fix this using a more generic approach.