Hello,

I have created a custom content with a Term reference field (with an autocomplete widget).
That term reference field is called 'test' for the example.

I would like to be able to have access to the name of the term parents with the token module.
How to do it?

In my 'token' help, there is just an entry test [node:field_test] Term reference field.
How to have access to its parents?

CommentFileSizeAuthor
#17 token-ref-multi-value-1487990-17.patch979 bytesoddz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Looks like a bug, I'm trying to understand why... and I will post a bug report.
By disabling/enabling the Entity Token, their is a tree under 'test' term reference field.

ckng’s picture

Title: Token for a term reference field » Token not working for a term reference field (multiple values)
Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Component: Documentation » Code
Category: support » bug

Having the same problem, but disabling/enabling the Entity Token does not solve it.

It turns out that when the term reference field is having multiple values, the token and sub-token are all missing.
e.g. you only get (note the underscore) that does not work

[node:field_test]

which should be

[node:field-test]
[node:field-test:name], etc

when multiple values setting is removed, the tokens reappear.

ckng’s picture

Title: Token not working for a term reference field (multiple values) » Token not working for term reference field (multiple values)
Project: Token » Entity API
Component: Code » Entity tokens

This belongs to Entity Tokens.
Latest dev solves the token tree not showing (as fixed in #1058856: Entity tokens not created for multi-value fields).

However, the replacement for the token failed.
e.g
[node:field-test:1:name]
[node:field-test:2:name]

So "list" for term reference field not quite working.

ezra-g’s picture

ezra-g’s picture

Title: Token not working for term reference field (multiple values) » Token not working for Entity reference field (multiple values)

I referenced this issue from a comment on #1834946: Implement email notifications & UI with Message Subscribe -- I believe the problem is the same -- The body token for a referenced entity isn't being replaced with a multi-value entity reference field. In my case, it references nodes.

aelling’s picture

I can confirm this is happening as well. For example if you implement a date field and check to "Include an end date" the field date tokens are not available for use. If you keep it just a single value field then the tokens are available for use.

rakun’s picture

Is there anything new about this?

Andre-B’s picture

this still bugs me. any news on this?

suldan’s picture

Even if #1520420: Entity tokens for multi-value fields still not working (or need documention) should be a duplicate of this, the problem is still unsolved. Need to get a single value out of a multiple value image field for og:image.

laura s’s picture

I'm running up against this as well. An ability to add an argument (e.g., ?0 for image 0) would be wonderful.

pbattino’s picture

Same here.

shortspoken’s picture

+ subscribing

ezra-g’s picture

In some cases, you may be able to resolve this issue by clearing the Entity load static cache before token replacement takes place. Here's how I resolved the problem in a very early Commons 3.x dev commit: http://drupalcode.org/project/commons_notify.git/blobdiff/2dc2468d7d5470....

jlyon1515’s picture

Issue summary: View changes

Has there really not been an update to this yet? I would like to be able to use something like:
[node:field-event-date:value:custom:m-d-Y]
in my alias replacement patterns, but when date is set to repeating or having a start and end date, tokens seem to no longer be available.
The patch here:
https://drupal.org/node/1440928#comment-7795885
does fix a fatal error from occurring if I've set my pattern incorrectly, but this token issue is still unresolved.

Matt B’s picture

Version: 7.x-1.x-dev » 7.x-1.5

This is in issue for me on 7.x-1.5

Collins405’s picture

Same problems

oddz’s picture

Looks like the problem was caused by the delta being incorrect. The fix is merely a matter of decrementing the delta by one.

kopeboy’s picture

What if I don't want to hardcode the delta value because I don't know how many values there are?

Is it possible to get all the names with a single token?

Currently I can get all the references but I cannot get a field of all the references.

Nathan Hall’s picture

I was working with autosku module to setup sku numbers correlating to the initial date of events. [commerce-product:field-event-date:value:custom:Ymd]

I found this thread and implemented the patch and immediately restored back to the baseline. I read the code again and found that the documentation of this feature seems to not articulate the use of multi-valued date/time well:

date:0:value (here 0 represents the first date with the starting time )
date:0:value2 (here 0 represents the first date with the ending time )
date:0:duration (here 0 represents the first date with the duration from start to finish )

increase the digit to reflect each additional day.

[commerce-product:field-event-date:0:value:custom:Ymd]

Works like a champ!

oddz’s picture

The patch I submitted six months ago hasn't made it core… (shrug)

ron_s’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Status: Active » Needs work

@oddz, thanks for taking time to investigate this. I added your patch to 7.x-1.6, and found that it caused problems when attempting to access date fields connected to another content type through Inline Entity Form (https://www.drupal.org/project/inline_entity_form).

When I had the patch included, I received no results from the token. Once the patch was removed, it worked correctly again.

Here is an example... a Date field (field_date) is attached to an Event content type, which is embedded in a Program content type via Inline Entity Form (and accessed through "field_events"). We're accessing the start date value from the Program by token:

[node:field-events:0:field-date:0:value]

So we're trying to display the 0th field_events attached to the Program, and the 0th field_date within that event.