To make this happen, you should either display the content using a php filter or use str_replace() in the preprocess function. You can also make simple text filter which can replace tokens [function:function_name] with the function result:
/** * Implements hook_filter_info(). */ function modulename_filter_info() { $filters['token_function'] = array( 'title' => t('Replace [function:*] to function result'), 'process callback' => 'mymodule_filter_process', 'cache' => FALSE, ); return $filters; } /** * Filter process callback. */ function mymodule_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) { $text = preg_replace_callback('/\[function:(.+?)\]/', function ($matches) { $token_params = explode(':', $matches[1]); $function = 'token_function__' . preg_replace('/[^a-z0-9_]/', '', $token_params[0]); if (function_exists($function)) { $arguments = isset($token_params[1]) ? explode(',', $token_params[1]) : array(); return call_user_func_array($function, $arguments); } return $matches[0]; }, $text); return $text; }
Instructions:
- Turn on the filter in the settings of the needed format.
- Write down the function with prefix token_function__, for example:
function token_function__current_date($format = 'r') { return date($format); }
- Add into the text a token in the following format [function:FUNCTION_NAME], for example [function:current_date].
Remarks:
You can pass arguments into the function as a third parameter and separate it with commas [function:FUNCTION_NAME:ARG1,ARG2], for example: [function:current_date:d.m.Y].
It is better to create a separate text format for the filter. This format will be used by the administrator exclusively and in specific nodes/blocks only, because the filter turns off caching of the text that passed through the format.