function ctools_set_callback_token
Set a replacement token from the value of a function during #post_render.
This function can be used like this: $token = ctools_set_callback_token('id', 'mymodule_myfunction');
Or this (from its use in ctools_page_title_content_type_render): $token = ctools_set_callback_token('title', array( 'ctools_page_title_content_type_token', $conf['markup'], $conf['id'], $conf['class'] ) );
The token (e.g: "<!-- ctools-page-id-1b7f84d1c8851290cc342631ac663053 -->") would then be replaced during post-render by the return value of:
ctools_page_title_content_type_token($value_markup, $value_id, $value_class);
Parameters
string $token: The token string for the page callback, e.g. 'title'.
string|array $callback: For callback functions that require no args, the name of the function as a string; otherwise an array of two or more elements: the function name followed by one or more function arguments.
NB: the value of $callback must be a procedural (non-class) function that passes the php function_exists() check.
The callback function itself will be called with args dependent on $callback. If:
- $callback is a string, the function is called with a reference to the render array;
- $callback is an array, the function is called with $callback merged with an array containing a reference to the render array.
Return value
string The constructed token.
See also
ctools_page_token_processing()
2 calls to ctools_set_callback_token()
- CtoolsPageTokens::testReplaceCallbackToken in tests/
page_tokens.test - Test that we can set page tokens.
- ctools_page_title_content_type_render in plugins/
content_types/ page/ page_title.inc - Output function for the 'page_title' content type.
File
-
./
ctools.module, line 450
Code
function ctools_set_callback_token($token, $callback) {
// If the callback uses arguments they are considered in the token.
if (is_array($callback)) {
$token .= '-' . md5(serialize($callback));
}
$string = '<!-- ctools-page-' . $token . ' -->';
ctools_set_page_token($string, 'callback', $callback);
return $string;
}