Current status of this issue:

- The standard way of providing tokens for fields like Date will be using the Token module, but the only thing currently supported is a default token format for the field as a whole. No way to indicate whether you want the start or end date or both or how you want it formatted, you get both dates formatted as the raw value stored in the field.

- Further work on Token module is blocked by questions about architecture and handling nested tokens and there has been no movement on them in quite some time. (see #1222592: Architecture RFC: Field token architecture and #1195874: Need to figure out how to create nested tokens from the array token type)

- An alternative way of handling tokens is provided by the Entity Tokens module (part of Entity API). It is fixed by the Entity patch at http://drupal.org/node/1058856#comment-5281650 in #1058856: Entity tokens not created for multi-value fields. If that gets committed, you can create Date tokens using Entity Tokens. The Entity Tokens are the ones that uses dashes instead of underscores in the token names.

- At the moment, Token and Entity Token are incompatible (see #1272560: Entity tokens duplicates field tokens created by token module because one defines tokens using underscores and one using dashes, resulting in duplication of all the field tokens, a big problem if there are lots of fields.

- Because of the conflict between Entity Tokens and Token noted above, it is possible Entity Tokens will change to using underscores, resulting in a need to change all your tokens, so you should keep an eye on #1272560: Entity tokens duplicates field tokens created by token module.

CommentFileSizeAuthor
#29 date-1103032-29.patch1.59 KBtim.plunkett
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnv’s picture

subscribe. I have some more messages:
Notice: Undefined index: date-field in _token_build_tree() (line 736 of \token\token.module).
Warning: Invalid argument supplied for foreach() in _token_build_tree() (line 736 of \token\token.module).
Notice: Undefined index: datestamp-field in _token_build_tree() (line 736 of \token\token.module).
Warning: Invalid argument supplied for foreach() in _token_build_tree() (line 736 of \token\token.module).
Notice: Undefined index: datetime-field in _token_build_tree() (line 736 of \token\token.module).
Warning: Invalid argument supplied for foreach() in _token_build_tree() (line 736 of \token\token.module).

joostvdl’s picture

subscribe

Issue also in token module announced: #1103286: Notices and warnings - date-field

metakel’s picture

Same error messages, but I got error at line 737.

BrightBold’s picture

subscribing

jeff_c’s picture

subscribe

BParticle’s picture

Subscribing

clauded’s picture

subscribe

sebish’s picture

Subscribe

joeyabbs’s picture

Subscribing

cutmedia’s picture

subscribing

sahaj’s picture

subscribing

bensnyder’s picture

subscribe

BrightBold’s picture

Just to add more details, I get the same errors as in #1. I am using the most recent versions of Date and Token — Date 7.x-2.x-dev from March 28 and Token 7.x-1.x-dev from Feb 25. The error seems to occur only on the Modules page whenever I enable a new module.

modstore’s picture

subscribe

rumblewand’s picture

subscribed

Steven.Pescador’s picture

Subscribing

acoustika’s picture

+1

Linus’s picture

+1

weri’s picture

Subscribing

zabelc’s picture

I'm seeing the same thing with the following:

date-7.x-2.x-dev (4/5)
token-7.x-1.x-dev (2/25)
Entity tokens-7.x-1.0-beta8 (3/21)

Oceanman’s picture

This is my error if I enable the Token module with these others.
Token 7.x-1.x-dev
Date 7.x-2.x-dev
Entity tokens 7.x-1.x-dev

* Notice: Undefined index: date-field in _token_build_tree() (line 736 of /token/token.module).
* Warning: Invalid argument supplied for foreach() in _token_build_tree() (line 736 of /token/token.module).
* Notice: Undefined index: datestamp-field in _token_build_tree() (line 736 of /token/token.module).
* Warning: Invalid argument supplied for foreach() in _token_build_tree() (line 736 of /token/token.module).
* Notice: Undefined index: datetime-field in _token_build_tree() (line 736 of /token/token.module).
* Warning: Invalid argument supplied for foreach() in _token_build_tree() (line 736 of /token/token.module).

This might be related to the solution to this but I'm not sure: http://drupal.org/node/1054812

zabelc’s picture

Based on Oceanman's link I think I've gotten rid of the errors.

In looking at date_token_info() in date.tokens.inc I noticed that only the $info['types']['date-field-value'] had any corresponding $info['tokens']['date-field-value'] entries; whereas date-field, datestamp-field, and datetime-field only appeared in $info['types'].

Thus I removed those types entries so that the function appears as follows:

/**
 * Implements hook_tokens_info().
 */
function date_token_info() {
  /* removed following
  $info['types']['date-field']
  $info['types']['datestamp-field']
  $info['types']['datetime-field']*/
  // All date types can share the same date value type.
  $info['types']['date-field-value'] = array(
    'name' => t('Date field values'),
    'description' => t('Tokens related to date field values.'),
    'needs-data' => 'date-field-value',
    'field-value' => TRUE,
  );
  // Provide two tokens: 'date' (the date or from-date), and 'to-date'.
  $info['tokens']['date-field-value']['date'] = array(
    'name' => t('Date'),
    'description' => t('The date value.'),
    'type' => 'date',
  );
  $info['tokens']['date-field-value']['to-date'] = array(
    'name' => t('To Date'),
    'description' => t('The to date value.'),
    'type' => 'date',
  );

  return $info;
}

While this does get rid of the errors, I wonder that it means that date-field, datestamp-field, and datetime-field won't be available as tokens (I don't think I'll be needing them but someone else might)

Dave Reid’s picture

Not sure why this chunk of code was committed to Date module for D7 already. Field token support is not yet ready nor fully baked in Token module: #691078: Field tokens

BrightBold’s picture

Awesome. Thanks Oceanman, zabelc, and Dave Reid for getting to the bottom of this. I'll be happy to get rid of those errors!

BParticle’s picture

Thank you all for helping me getting rid of those errors! Works for me!

pauljr8’s picture

Hello, I am interested in what the final verdict is on this problem. Is the fix mentioned above by zabelc the final answer? If so, how would I implement it, e.g. which file to alter? Or, if a fix is in the works and forthcoming, please advise and I'll be quiet and wait for it.
Thanks

BrightBold’s picture

@pauljr8 - It looks like you have three choices (@DaveReid correct me if I'm wrong!):

  1. You can either apply zabelc's patch in #22, which essentially rolls back the changes to Date made in #906622: Cleanup the token code, or
  2. You can patch Token module with #691078-92: Field tokens which I think in conjunction with the changes to Date that were committed prematurely, will work to provide field tokens for Date, or
  3. You can wait until one or the other of those changes gets implemented in its respective module.

Since I only get the errors on the Modules page, I may actually go with #3, trusting it will sort itself out eventually.

pauljr8’s picture

Thanks. Waiting for the upgrade makes sense to me as well.

tim.plunkett’s picture

Status: Active » Needs review
FileSize
1.59 KB

Patch to hold everyone over until #691078: Field tokens is in.

HnLn’s picture

sub

KarenS’s picture

Status: Needs review » Fixed

Commit the patch in #29. If there is something else to be done let me know.

tim.plunkett’s picture

For future reference, using `git am date-1103032-29.patch` would give proper git credit when the patches are rolled with headers like that one.

basicmagic.net’s picture

subscribe

KarenS’s picture

The git instructions say to use "Issue #1103032, by tim.plunkett...", which is what I did.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Starminder’s picture

Status: Closed (fixed) » Active

prematurely closed -

tim.plunkett’s picture

Status: Active » Closed (fixed)

@starminder
In what way?

Starminder’s picture

In one of the other threads concerning date, if you use the release version you get different errors and the recommendation is to use the dev version. If you use the dev version you get this. Rock or hard place.

bfroehle’s picture

Title: Undefined index: date-field in _token_build_tree() » Re-Add Field Token Support
Status: Closed (fixed) » Postponed
Issue tags: +field tokens

Okay, so token support is currently blocked on #691078: Field tokens, but when that goes in, we can simply revert the patch in #29 to get basic field token support.

sachbearbeiter’s picture

subscribe

davidd07’s picture

The title of this thread is "Re-Add Field Token Support" but all I can see is the opposite, removing token support. I actualy need token support for the DATE module, so I can use in paths. I have applied the most recent patch for token http://drupal.org/node/691078 This allows me to see all node fields, however still no Date field, in path auto token list. Only default Drupal dates. Any help much apprectiated. I have installed Date 7.x-2.x-dev

tim.plunkett’s picture

@davidd07, it was removed since #691078: Field tokens isn't committed yet, and the code was broken. Once that issue is fixed, the date token support can be readded.

hansfn’s picture

subscribe

Shadlington’s picture

Subbing

adamdicarlo’s picture

OT: @KarenS, see http://drupal.org/node/1146430 -- I've been wondering recently how to give proper attribution to patch authors, so I just dug that up after seeing tim.plunkett's comment here. As far as I understand it, d.o will actually use the commit's metadata and credit the commit to the author rather than the committer.

KarenS’s picture

I have been following the instructions at http://drupal.org/project/date/git-instructions. If I'm supposed to be doing something different someone should change that information.

KarenS’s picture

Plus I can't tell from that link how I know which way the patch was created. And if I'm supposed to do the second option I have to go find the patch author's email address, which ordinarily isn't available anywhere, so I don't know how I'd do that either.

I'm already struggling with patches created different ways that have to be applied different ways. I'm more than happy (delighted! excited!) to get other people making patches, and I want to give them credit for doing so, but all of this means it's taking a lot more time to review and commit patches.

The last patch I committed cost me a half hour of screwing around to find the right way to apply it and give the author credit, and then I still got it wrong :(

tim.plunkett’s picture

In the case of http://drupal.org/files/issues/date-1103032-29.patch, the header part with my name and email address signifies it can be applied with git am foo.patch, otherwise you'd have to go look it up and do git apply foo.patch && git commit --author ...

Which is confusing and time consuming and not really documented! Which is why I don't take offense when someone doesn't commit my patches that way. Also, it only works when one person wrote the patch, because you can't list more than one author. So not really a big deal.

Anyway, thanks for caring/responding about this Karen. I can't wait to roll the next patch for this issue!

wjaspers’s picture

subbing.

mariagwyn’s picture

sub

JamFar’s picture

Boy, if even KarenS struggles with making and applying these patches, maybe Dries needs to rethink how this is being done and get it simplified for everyone?

tim.plunkett’s picture

@JamFar, it has nothing to do with KarenS "struggling", or Dries "rethinking". It's merely a documentation issue, which anyone can contribute to. Please don't be so disparaging.

MrPaulDriver’s picture

Please would someone mind advising me of the latest with this issue.

From what I read the changes for Issue #691078: Field tokens have now been implemented as of Aug 17, the current release being Token Beta 5. And, as far as I can see, the Date token is now available.

If this is the case. Is the patch at #29 still relevant? - I notice that tim.plunket says [it is a] "Patch to hold everyone over"

Without applying any patch, I find that Date token still doesn't print (for me).

So where to go now? Any help much appreciated.

KarenS’s picture

The only thing that has hit so far is a basic plain text field. We need to add a 'default token formatter' to the Date module that provides the raw value in the date field as its output. That is way short of what is really needed here, which are ways to allow you to do things like create tokens that display the token in some specified format, properly taking into account things like the timezone and granularity of the field. Those things are waiting on #1222592: Architecture RFC: Field token architecture and #1195874: Need to figure out how to create nested tokens from the array token type.

So this is still postponed.

KarenS’s picture

And to clarify, the 'Patch to hold everyone over' was a patch to completely remove token support until it's working, so you don't need to apply any patch (it's already applied) and you will not see any tokens until the core issues are resolved.

MrPaulDriver’s picture

Thank you Karen.

I didn't realise the complexity and look forward to seeing the issue resolved.

bennybobw’s picture

subbing

kenianbei’s picture

subscribe

webchick’s picture

Tagging.

KarenS’s picture

As a temporary measure, I added a new date plain formatter that just spits out the stored value of the date field, whatever it is. It does not timezone conversion, no formatting of the output, just the raw value. Not sure how useful that is but doing much more would require the Token field support that isn't working yet so you could choose exactly what you want done with it.

fago’s picture

FYI, date tokens already work via the entity tokens module (shipping with the entity api). In case the date field is multiple though, the patch from #1058856: Entity tokens not created for multi-value fields is required.

KarenS’s picture

But all Entity token does is give us the raw value of the date. There is no way to select a format for the date or anything else.

Dig1’s picture

The entity tokens module is a neat alternative to use as long as you do not need an end date.

If you need an end date then as per #61 a patch is needed. Unfortunately neither of those patches work at the moment, I got:

patch < entity_list_tokens_2.patch
patching file entity_token.tokens.inc
Hunk #2 FAILED at 62.
1 out of 4 hunks FAILED -- saving rejects to file entity_token.tokens.inc.rej 

and

patch < entity_list_tokens.patch
patching file entity_token.tokens.inc
Hunk #1 succeeded at 33 (offset -1 lines).
Hunk #2 FAILED at 63.
Hunk #3 succeeded at 123 (offset -1 lines).
Hunk #4 FAILED at 156.
Hunk #5 succeeded at 180 (offset -6 lines).
2 out of 5 hunks FAILED -- saving rejects to file entity_token.tokens.inc.rej 

Cheers

fago’s picture

>But all Entity token does is give us the raw value of the date. There is no way to select a format for the date or anything else.

All regular date token replacements as defined by system.module are available via token chaining, but I think token module also exposed more stuff like the custom date formats.

BrightBold’s picture

All regular date token replacements as defined by system.module are available via token chaining, but I think token module also exposed more stuff like the custom date formats.

Right — in Pathauto, I can set a path for article/[node:created:custom:Y]/[node:created:custom:m]/[node:created:custom:d]/[node:title] but even with Entity Tokens enabled, calendar/[node:field_event_date:custom:Y]/[node:field_event_date:custom:m]/[node:field_event_date:custom:d]/[node:title] gives me an invalid token message. So it seems to me we still really need this functionality!

fago’s picture

[node:field_event_date:custom:d] is probably provided by the token module, entity tokens uses dashes. Try [node:field-event-date:custom:d]

KarenS’s picture

If I enable Entity Tokens, no date tokens other than the top-level one ([node:field_date]) appear in the replacement patterns. If I just try to force in value in the pathauto settings like [node:field-date:custom:d], I get errors like 'The Default path pattern for Date (applies to all Date content types with blank patterns below) is using the following invalid tokens: [node:field-date:custom:d].';

What am I missing?

KarenS’s picture

Tried another installation and it worked better. Dates that have no ending date had nested tokens. Dates with an ending date had none. And for the ones where the nested tokens get added there are two, on with underscores and one with dashes. And they both show up as being expandable even though only the one with dashes is actually expandable (probably because they have the same id in the source code).

Anyway I'll have to try to sort out what is the difference between the site that works and the one that doesn't.

KarenS’s picture

OK, the difference between the dates that work and the ones that don't is that the working dates have 'date' properties and the non-working ones have 'struct' properties in the array created by entity_get_all_property_info().

I think this goes back to the way the Date property setter callback works, which is code I am completely unfamiliar with. The related issue is probably #1153766: provide a property setter callback.

If that could be fixed by someone who understands that part of the code we can say that tokens will work if you use the Entity Tokens module, which would keep this issue from blocking a release. Then when the Token module gets nested field token support working we can do whatever is needed to incorporate that.

fago’s picture

ah, yes there is still #1183676: improve support for arbitrary data structures. If you have a start and an end-date, there is no simple "date" property but a struct containing both dates. In that case tokens do not yet work - I'll have a look at that.

fago’s picture

#1058856-22: Entity tokens not created for multi-value fields contains a patch for entity-tokens, what makes list-tokens work and adds basic data-structure-token support. Thus with that patch, you should get working date-tokens (using the "dash-ed" field names) - please test!

BrightBold’s picture

Is this dependent on a certain version of Date? I am using the latest version of Entity with the patch (and hyphenated tokens) but still get an error. It occurs to me that I froze Date at alpha3 until Calendar 7.3 is a little farther along (because I know it's recommended to upgrade them in tandem, so since they are working fine now I thought I'd sit tight until Calendar looked stable). I want to help test this but shouldn't be weighing in if the fact I'm using an older version of Date means I won't get accurate results.

KarenS’s picture

You should be using latest dev version of Date and Entity and Token for testing things like this. And you shouldn't be testing them on a production site, try it on a test site with the dev versions of everything.

I had some success with that patch but still some problems, and I commented on that issue.

KarenS’s picture

Current status of this issue:

- The standard way of providing tokens for fields like Date will be using the Token module, but the only thing currently supported is a default token format for the field as a whole. No way to indicate whether you want the start or end date or both or how you want it formatted, you get both formatted in as the raw value stored in the field.

- Further work on Token module is blocked by questions about architecture and handling nested tokens and there has been no movement on them in quite some time. (see #1222592: Architecture RFC: Field token architecture and #1195874: Need to figure out how to create nested tokens from the array token type)

- An alternative way of handling tokens is provided by the Entity Tokens module (part of Entity API). It too is broken at the moment but fago is working on the issue so hopefully that will be fixed soon. See #1183676: improve support for arbitrary data structures)

- At the moment, Token and Entity Token are incompatible (see #1272560: Entity tokens duplicates field tokens created by token module because one defines tokens using underscores and one using dashes, resulting in duplication of all the field tokens, a big problem if there are lots of fields.

I'm going to copy this information into the issue summary.

KarenS’s picture

Priority: Normal » Critical
Status: Postponed » Active

Also back to critical

tim.plunkett’s picture

Issue summary: View changes

Update the issue summary

KarenS’s picture

Issue summary: View changes

Update for possible fix for Entity Tokens

KarenS’s picture

Entity tokens are now working using the patch at http://drupal.org/node/1058856#comment-5281650. If that gets committed you can create Date tokens using the Entity Tokens module (part of http://drupal.org/project/entity). The Entity tokens are the ones that use dashes instead of underscores in the names.

Because of the conflict between Entity Tokens and Token noted above, it is possible Entity Tokens will change to using underscores, resulting in a need to change all your tokens, so you should keep an eye on #1272560: Entity tokens duplicates field tokens created by token module.

KarenS’s picture

Issue summary: View changes

Add note that Entity Tokens may change to using underscores.

mariagwyn’s picture

Karen,

I have just installed the dev version of entity and am running the alpha5 version of date. I am trying to get this url pattern:

meetings/[node:field-sess-assoc-meeting:field_event_dates]/papers/[node:title]

to be this:

meetings/[node:field-sess-assoc-meeting:field_event_dates:custom:Y]/papers/[node:title]

If I read your post above correctly, this should work: "meetings/[node:field-sess-assoc-meeting:field-event-dates]/papers/[node:title], but this generates an error. What am I missing? should I be on the dev version of date? Should I construct the pattern differently? Do I need to turn something off (token...)? Or have I jumped the gun on custom dates....

Thanks,
Maria

quick followup: with the dashes, no error is genderated, but the value is this: "property-fieldeventdates" in the token spot of the url.

mariagwyn’s picture

Another update: the token does work, but the custom:y does not.

So, did I jump the gun on the custom part, or am I missing something that will get this to work?

Maria

mariagwyn’s picture

First, let me apologize: I try something, test, doesn't work, then post a comment. Then I walk away from my desk in disgust. Then I come back, and lo and behold, try something else, and it DOES work.

Second: custom dates do work. This gets exactly what I want: meetings/[node:field-event-dates:value:custom:Y]/details

KarenS’s picture

Notice the difference between "field_event_dates" and "field-event-dates". The first is what Token module provides and it does not work. The second is what Entity Token provides and it does work. The fact that there are two different patterns for the same field is the conflict problem that needs to be resolved, it is both confusing and creates performance problems (the tokens are duplicated).

And the 'walk away and it starts to work' may be that the cache needed to be cleared.

mariagwyn’s picture

Karen,

I did notice the difference between the two, and had it working with the hyphens. Now, with the recent date upgrade, I am having problems. Sigh.

Until the update, this worked:
meetings/[node:field-event-dates:value:custom:Y]/details

Now, all that works is this:
meetings/[node:field_event_dates]/details, which is the Token module, not the entity module.

Is this b/c the entity tokens and date module are not playing well together? Or do you know of another change?

KarenS’s picture

I'm not sure exactly what 'the recent Date upgrade' means. Are you using the latest dev code or the older alpha release? Be sure you have the latest dev version of all the related modules, I have no idea what will work otherwise. If there's still a problem there, some change may have introduced a new problem, but please confirm that.

mariagwyn’s picture

recent dev version of Date, showing errors. I just uploaded the most recent dev, from Dec 14.

mariagwyn’s picture

I take it back. with dev versions of all related modules, seems to be working fine. sorry, forgot to move the others to dev rather than rc's.

KarenS’s picture

Since there is a work-around, I'm taking this off the list of release blockers.

Kevin Morse’s picture

Hi guys,

I need to implement the following for Pathauto

events/[node:field-dateandtime:value:custom:Y]/[node:title]

What steps/modules need to be installed to do this?

My Date field has year, month, day, hour, min and start and stop times.

Thanks for your help.

fago’s picture

- Because of the conflict between Entity Tokens and Token noted above, it is possible Entity Tokens will change to using underscores, resulting in a need to change all your tokens, so you should keep an eye on #1272560: Field token conflict between entity_tokens and token module.

I don't think this will be an issue. Even *if* we would change it to do so for whatever reason, we would keep dashed tokens working too.

mattbk’s picture

subscribe

KarenS’s picture

You don't need to 'subscribe', just use the 'Follow' link at the top of the issue. That way everyone who is following won't get emailed every time someone else subscribes. Thanks!

NicolasH’s picture

So with the regular token I get a start and an end date (if one was specified).

[node:field_event_date]  ... 2012-02-15 04:45:00 to 2012-02-23 04:45:00

However, the timezone is out.

Entity tokens appear to do a proper timezone conversion, but AFAICT they wouldn't allow for an optional end date (without having a " to " there - I can't use conditionals where this gets displayed).

[node:field-event-date:value:custom:Y-m-d] [node:field-event-date:value:custom:H:i:s] to [node:field-event-date:value2:custom:Y-m-d] [node:field-event-date:value2:custom:H:i:s]

Any ideas?

KarenS’s picture

The thing you're trying to do in #92 is probably not possible currently. We need better tokens, but it's pointless to add any code for this until the underlying modules are finished, because the final changes may end up breaking anything we try to do in the interim.

NicolasH’s picture

Thanks Karen, getting by for now with hook_tokens_alter() then...

bryancasler’s picture

The following work for me

[node:field-class-date-time:value:custom:Y]-[node:field-class-date-time:value:custom:m]-[node:field-class-date-time:value:custom:d]
[node:created:custom:Y]/[node:created:custom:m]/[node:created:custom:d]
BrightBold’s picture

Aah! Thanks @animelion — I was missing value: — that appears to be why mine weren't working. Awesome to have this fixed before the site goes live!

pyrello’s picture

This also worked for me:

[node:field-class-date-time:value:custom:Y-m-d]
liquidcms’s picture

sorry, but can someone summarize what is required to piece this together?

this is what i have:

- latest -dev of Date
- latest -dev of Entity API (also latest -dev of i18n since without it e-api crashes the site: #1462984: Internal Server Error with latest dev)
(flushed caches)

i still only get the same tokens (for ANT) that i had before all of this, at least as far as what is listed under Replacement Patterns:

Date	     [node:field_appmt_date]	Date (Unix timestamp) field. 

i have no field based tokens with "-".

are they possibly not listed and we just need to guess at the format?

as in #95 above i tried this:

[node:field-appmt-date:value:custom:Y]

this doesn't work.

KarenS’s picture

#98 - you have to enable the 'Entity Tokens' module, as noted in the issue summary above. That is what creates the tokens that use '-'.

liquidcms’s picture

yes, sorry... that is also enabled. and it is the latest since it comes with Entity API (which is latest -dev)

this screen mostly shows the issue: http://screencast.com/t/OJHvc9R2OFgo

perhaps interference with some other module? entity cache, entity translation?

yankozmo’s picture

I have the impression the 7.x-2.3 release broke the functionality: I had it up and running, but after updating to 7.x-2.3, said tokens don't seem to be working any more.

YK

videographics’s picture

With 7.x-2.3 and Entity Tokens 7.x-1.0-rc1 I've got formatting options in the entity listing for 'Date created' and 'Date changed', but (similar to #100) I've get nothing for my date fields. Manually typing stuff like [node:field-class-date-time:value:custom:Y-m-d] doesn't work for me either.

I too remember this working at some point...

KarenS’s picture

Status: Active » Postponed

Entity Tokens got broken by #1266688: Support microdata in date fields, I need to revert that. Please keep this issue focused on the Token module tokens. That is the 'token support' that we can't do until the token module is updated.

KarenS’s picture

I created a separate issue about problems with Entity Tokens at #1530042: Get Entity Tokens working. Let's keep this issue focused on getting Token module tokens working.

videographics’s picture

Thanks Karen! http://drupal.org/node/1530042 makes it real clear.

langworthy’s picture

What's the status of this issue? I found it after noticing that auto_nodetitle was not converting a date field to the proper timezone. Am I in the right place? :)

klonos’s picture

#1058856: Entity tokens not created for multi-value fields got committed. The project page still states that "Token support is not working in D7" and points to this issue here and its summary. So, the part that says one should apply the patch in that issue should be updated.

I have gone through that issue and it states that it got fixed by a commit for #1356006: Fix entity property info of product / customer profile / line item reference fields (so the issue should not be present in Entitty API 7.x-1.0), but some users do report issues like #1440928: Entity tokens for multi-value fields produce a fatal error.

@KarenS: So, should we replace the section in the issue summary to point people to that issue instead?

kclarkson’s picture

I am really confused by all of these cross posted issues.

So is the current issue summary up to date ?

Also seeming Date is in Core for D8 is there a way to escalate the issue ?

I would think that being able to use date tokens from a custom date field is a "huge" necessity.

Thanks again,

kclarkson’s picture

Issue summary: View changes

Fix typos

klonos’s picture

Any update regarding this would be greatly appreciated. Especially if I could get some answers on my questions in #107, I could then update the issue summary.

Thanx in advance.

justdave’s picture

So since all the paths seem to lead to this ticket for people trying to get date tokens to look correct in email templates, this is probably the best place to share what I figured out in my email templates to make the dates look correct.

[node:field-date:value:custom:D, M j, Y]{{[node:field-date:value:custom:Hi]==0000?: - [node:field-date:value:custom:g:i A]}}{{[node:field-date:value:custom:YmdHi]==[node:field-date:value2:custom:YmdHi]?: to {{[node:field-date:value:custom:Ymd]!=[node:field-date:value2:custom:Ymd]?[node:field-date:value2:custom:D, M j, Y]{{[node:field-date:value2:custom:Hi]==0000?: - [node:field-date:value2:custom:g:i A]}}:[node:field-date:value2:custom:g:i A]}}}}

This uses medium date formats (Mon Dec 3, 2013 - 7:00 PM)
It leaves off the time and shows only the date for an all-day event. If leaves off the end time if there isn't one. It shows the date range for multi-day events. It leaves off the date and shows only the time on the end time if it's on the same day as the start time.

It doesn't show any timezones... on my site it was unneeded because it's for a local group where all members are guaranteed to be in the same timezone. It makes the horrible assumption that any date that's midnight is going to be an all-day date. This seems like a Bad Thing to me, but I couldn't figure out any other way to determine that.

Renee S’s picture

Thanks, justdave, that's really helpful. AFAIK the "midnight" assumption is also baked into the "All day" checkbox in Date itself, so even if it's a Bad Thing, it's not unprecedented ;)

bmateus’s picture

Issue summary: View changes

For those searching to just custom format your Date field on your emails using EntityForms with EntityNotifications, the token that worked for me was [entity:field-date:custom:l, j F Y]

Using "value", as in [entity:field-date:value:custom:l, j F Y] didn't work at all.

I guess I'm using Tokens only, since they have hifens instead of underscores (which should mean EntityTokens?).

mxh’s picture

By using the modules

  • Date 7.x-2.7
  • Entity API (incl. Entity tokens) 7.x-1.5
  • Rules 7.x-2.7

creating a Date field of type Unix timestamp and setting up a rule, I'm (currently) able to format the date value with this token pattern:

[node:date-field:0:custom:Y]
stewart.adam’s picture

#113 not working for me in the pathauto alias settings, using Date 7.x-2.8 and Entity 7.x-1.5. Date field is multi-value.

Edit: Ignore above, managed to get it working with a combination of regular token and entity_token syntax: [node:field-date:0:value:custom:Y-m-d] works for a multi-valued date field.

svogt0511’s picture

Ref above:

Edit: Ignore above, managed to get it working with a combination of regular token and entity_token syntax: [node:field-date:0:value:custom:Y-m-d] works for a multi-valued date field.

I used that to get it working, as well.

What was being displayed for replacement tokens for referencing the start/end dates in my date field was wrong. It took quite quite a bit of searching to come up with this solution.

Perhaps I have the wrong versions of modules. I am still fairly new to drupal.

BigBrother2010’s picture

Token works but without "value" as part of the token for me. Still i cant get multi-value to display. I have 3 dates, but only first one is showing.

ShaneOnABike’s picture

Edit: Ignore above, managed to get it working with a combination of regular token and entity_token syntax: [node:field-date:0:value:custom:Y-m-d] works for a multi-valued date field.

I can confirm that this does work while it is not shown actually!

But just remember you need to use the selector node:::value:custom:

By item # I mean the date item in the array.

@KarenS: Can you document this on the front Date page or the README since I think it's fairly important for folks.

Christopher Riley’s picture

I am noticing that it is giving the wrong date. I am thinking it is a timezone thing, suggestions?

alysaselby’s picture

#117 worked for me. Thanks this was the one combo I had not tried.

[node:field-date:0:value:custom:Y-m-d] works for a multi-valued date field

I should also add that for schema.org events I needed the start and end date to display separately in ISO format and this worked:

Start: [node:field-event-date:0:value:custom:c]
End: [node:field-event-date:0:value2:custom:c]

DamienMcKenna’s picture

Title: Re-Add Field Token Support » Document how to use date tokens
Component: Code » Documentation
Category: Bug report » Task
Priority: Critical » Normal
Status: Postponed » Active

So it looks like we need a documentation task rather than a critical bug report.

chicagomom’s picture

As #118, my experience is that token in format [node:field-date:0:value:custom:Y-m-d] gives output but is off by time zone difference (in my case, site regional timezone set to UTC-6 (Chicago), so an event on 8 Jan 7pm gets returned as 9 Jan 1am.

(7.x-2.10 doesn't do this.)

asb’s picture

No luck to extract the year segment from a date field with something like [node:field-release-date:0:value:custom:Y] or [node:field_release_date:0:value:custom:Y].

The only thing working is what the tokens browser is listing - [node:created:custom:Y]. Though, this syntax doesn't work either for date field values (e.g. [node:field_release_date:custom:Y]).

Using drupal core 7.61, 'date' 7.x-2.10, 'token' 7.x-1.7.

Tried to enable 'Entity tokens' from Entity API 7.x-1.9, but this breaks ./admin/structure/types/manage/….

Considering the original topic of this issue - "Document how to use date tokens" from March 2011 -, could anyone please give a summary which version of which module is supposed to give which result?

Currently, trying to work with tokens is a bit like playing string lottery. You might win sometimes, but you need to play a looooot of combinations…

Thank you!

loudpixels’s picture

Is it possible to use a date token with an offset? I'm trying to auto-generate a node title with tomorrow's date. something like: [date:long] + 1 day? Any help or pointers would be greatly appreciated.