So, Drupal gives you the ability to define your own custom date formats and to give them designated names (admin/settings/date-time/formats). It would be really great if anytime a new format was added (let's say I want long, medium, short, and a new one called longer) that each of these would have token equivalents through token_get_date_token_info/values so that any module using these function to create their date tokens would have access to token of any of the system defined date formats (like scheduler).

CommentFileSizeAuthor
#6 token_date.patch3.11 KBsirkitree
#4 token_date.patch2.49 KBsirkitree

Comments

sirkitree’s picture

Hrm, upon closer inspection it seems this menu item is actually part of date_api.module, not core...

sirkitree’s picture

... Which only operates on 'field' types, not 'node' which is what I was hoping for...

Wondering if it would be acceptable to just module_exists('date_api') and still include this within token_get_date_token_info/values

sirkitree’s picture

[edit] double post

sirkitree’s picture

Status: Active » Needs review
StatusFileSize
new2.49 KB

Here's a patch - this successfully pulls in any custom date formats you create through date_api which any module utilizing token_get_date_token_info/values can then have tokens for...

Custom date formats:
Only local images are allowed.

Corresponding tokens:
Only local images are allowed.

Example of Scheduler which utilizes token_get_date_token_info/values for it's publishing tokens:
Only local images are allowed.

And a final end result where the new custom 'longer' token is being rendered:
Only local images are allowed.

dave reid’s picture

Status: Needs review » Needs work

I'm worried about this slowing down token. We're already generating every single token possible. Plus this definitely has to re-roll against the lastest 6.x-1.x code because there have been a lot of recent changes to date token generation (i.e. we have our own token_format_date() that should be used). Also, doesn't the 'short' token conflict with the 'small' token? Also the descriptions need to re-use the $description parameter in token_get_date_token_info().

sirkitree’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB

I know what you mean about slowing token down - and ideally this would go into date module, except there is no way presently to extend these functions. Date could provide these in it's hook_token_info, but any module using token_get_date_token_info/value directly will then not benefit from custom formats.

One possibility would be to create a small submodule to encapsulate this functionality, token_date or something, but would still require a hook within token_get_date_token_info/value to allow extension. This would have the effect that a use would need to enable the submodule and therefor (hopefully) be aware that they are adding processing of a significant nature - but that seems a bit overkill for the amount of overhead that module_exists() might create.

In anycase, here is an updated patch against 6.x-1.x

Results:
Only local images are allowed.

Also - now removes the date format small if date_api enabled.

dave reid’s picture

Status: Needs review » Needs work
+++ token.moduleundefined
@@ -490,7 +501,43 @@ function token_get_date_token_values($timestamp = NULL, $token_prefix = '', $lan
+        $format = variable_get('date_format_' . $type, array_shift(array_keys($formats)));
+        $ts = date_convert($timestamp, DATE_UNIX, DATE_DATETIME);
+        $tokens[$token_prefix . $type] = date_format_date($ts, 'custom', $format);

This should just be adding the formats into the array, not actually doing replacement as this will only be executed once per request.

Powered by Dreditor.

dave reid’s picture

Issue tags: +6.x-1.16 blocker

Adding new release blocker tag.

dave reid’s picture

Issue tags: -6.x-1.16 blocker

I reverse myself on the blocker tag.

bluegeek9’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)