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

febbraro’s picture

sub

Dave Reid’s picture

Component: Documentation » Code
Status: Active » Postponed

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

e2thex’s picture

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

Dave Reid’s picture

Status: Postponed » Closed (won't fix)

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

Summit’s picture

Hi, is this module build, so I can capitalize the first letter of a token?
greetings, Martijn