Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
So have been working on a module to allow tokens to be linked to a php function.
The basic idea is that when one defines the token they add an addition param of function which is a callback to be used.
$info['tokens']['f']['cap'] = array(
'name' => t('Capitalize'),
'description' => t("Capitalizes the value. ") . token_function_help(1),
'dynamic' => TRUE,
'function' => 'strtoupper',
);
so cap would take what ever the X in [f:cap:X] and capitalize it.
one can use multiple params separated by :
and one can use tokens but they need to be wrapped in {} instead of []
I have the module here https://github.com/phase2/token_function
git://github.com/phase2/token_function.git
I want to see it you think it would be good to be part of token before i post it as its own module.
Comments
Comment #1
febbraro CreditAttribution: febbraro commentedsub
Comment #2
Dave ReidAn interesting idea but it may be good to let this simmer in another module for a bit - there may be security issues.
I also checked out the code - you should note that we already support current-page:arg tokens in Token.module itself.
Comment #3
e2thex CreditAttribution: e2thex commented@dave sound good I will put it up as it's own module.
The current-page:arg is for the drupal path, not for the alias url i believe. So if article/baseball-rocks is the alias for node/5 current-page:arg:1 = 5 where current-page:url-arg:1 = baseball-rocks.
My use case is for some some omniture work where they are looking at parts of the aliased path, so I the internal drupal path is not appropriate.
Thanks for taking a look.
Comment #4
Dave ReidNote that when #1198034: The [current-page:url tokens not working and #1229626: Add an [url:unaliased] url token and move [current-page:arg] to [url:args] as an array token are committed, then you should be able to use [current-page:url:arg:1] to get 'baseball-rocks' in your use case.
Comment #5
Summit CreditAttribution: Summit commentedHi, is this module build, so I can capitalize the first letter of a token?
greetings, Martijn