function theme_token_insert_tree in Token Insert 7.2
3 theme calls to theme_token_insert_tree()
- token_insert_text_table in token_insert_text/
token_insert_text.module - token_insert_wysiwyg_page in token_insert_wysiwyg/
token_insert_wysiwyg.module - _token_insert_ckeditor_tokens_output in token_insert_ckeditor/
token_insert_ckeditor.module - Print out the tokens in a CKEditor-readable format.
File
- ./
token_insert.module, line 170 - wysiwyg plugin hook.
Code
function theme_token_insert_tree() {
$roles = array();
if (variable_get('token_insert_use_tokens_per_role', 0)) {
global $user;
$roles = array_keys($user->roles);
}
$roles[] = 'global';
sort($roles);
// Use the token cache bin. This way, whenever token cache gets cleared, the
// token insert tree gets cleared as well.
$element = array(
'#cache' => array(
'cid' => 'tree-rendered:token-insert-tree:' . implode('-', $roles),
'bin' => 'cache_token',
),
);
if ($cached_output = token_render_cache_get($element)) {
return $cached_output;
}
module_load_include('pages.inc', 'token');
module_load_include('inc', 'token_insert');
$info = token_get_info();
$options = array(
'flat' => FALSE,
'restricted' => FALSE,
'depth' => variable_get('token_insert_max_depth', 1) <= 0 ? 1 : variable_get('token_insert_max_depth', 1),
);
$tokens = token_insert_get_tokens(TRUE);
foreach (token_insert_get_allowed_token_types() as $token_type) {
$row = _token_token_tree_format_row($token_type, $info['types'][$token_type], TRUE);
unset($row['data']['value']);
$tree = token_flatten_tree(array_intersect_key(token_build_tree($token_type, $options), $tokens));
if ($tree) {
$rows[] = $row;
foreach ($tree as $token => $token_info) {
if (!isset($token_info['parent'])) {
$token_info['parent'] = $token_type;
}
$row = _token_token_tree_format_row($token, $token_info);
unset($row['data']['value']);
$row['data']['token']['data'] = '<a href="#" title="' . t('Insert this token into your form') . '">' . $token . '</a>';
$rows[] = $row;
}
}
}
$element += array(
'#theme' => 'tree_table',
'#header' => array(
t('Name'),
t('Token'),
t('Description'),
),
'#rows' => $rows,
'#attributes' => array(
'class' => array(
'token-tree',
'token-insert-table',
),
),
'#empty' => t('No tokens available'),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'token') . '/token.js',
),
'css' => array(
drupal_get_path('module', 'token') . '/token.css',
),
'library' => array(
array(
'token',
'treeTable',
),
),
),
'#caption' => t('Click a token to insert it into the field.'),
'#click_insert' => FALSE,
);
$output = drupal_render($element);
token_render_cache_set($output, $element);
return $output;
}