function js_get_token in JS Callback Handler 7.2
Generate a unique token for JS callbacks.
Parameters
string $module: The module name the callback belongs to.
string $callback: The callback name.
Return value
string|array If $module and $callback are provided the unique token belonging to it is returned, otherwise all current tokens set are returned.
3 calls to js_get_token()
- js_preprocess_html in ./
js.module - Implements hook_preprocess_html().
- js_pre_render_element in ./
js.module - Generic #pre_render callback.
- js_process_autocomplete in ./
js.module - Autocomplete #process callback.
File
- ./
js.module, line 885 - JavaScript callback handler module.
Code
function js_get_token($module = NULL, $callback = NULL) {
// Use the advanced drupal_static() pattern, since this has the potential to
// be called quite often on a single page request.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['tokens'] =& drupal_static(__FUNCTION__, array());
}
$tokens =& $drupal_static_fast['tokens'];
// Return a specific token for a module callback.
if (!empty($module) && !empty($callback)) {
// Only authenticated users should be allowed to generate tokens.
if (!user_is_anonymous()) {
return $tokens["{$module}-{$callback}"] = drupal_get_token("js-{$module}-{$callback}");
}
else {
return FALSE;
}
}
// Otherwise return all tokens.
return $tokens;
}