Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions templates/token-tree.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#
/**
* @file
* Default theme implementation to present token tree data.
*
*
* Available variables:
* - content: A list of content items. Use 'content' to print all content, or
* print a subset such as 'content.field_example'.
* @see template_preprocess_token_tree()
*
* @ingroup themeable
*/
#}

<article{{ attributes }}>
{{ content }}
</article>
15 changes: 15 additions & 0 deletions templates/tree-table.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{#
/**
* @file
* Default theme implementation to present token table.
*
*
* Available variables:
* - content: A list of content items. Use 'content' to print all content, or
* print a subset such as 'content.field_example'.
* @see template_preprocess_token_table()
*
* @ingroup themeable
*/
#}
{{ content }}
17 changes: 11 additions & 6 deletions token.module
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ function token_help($route_name, RouteMatchInterface $route_match) {
// return a TRUE value if this is not actually the help page.
return TRUE;
}
$output = '<dl>';
$output .= '<dt>' . t('List of the currently available tokens on this site') . '</dt>';
// ToDo: Use render arrays. See https://drupal.org/node/2195739
$output .= '<dd>' . _theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '</dd>';
$output .= '</dl>';
return $output;
$output = [];
$output['#prefix'] = t('List of the currently available tokens on this site');

$output['content'] = [
'#theme' => 'token_tree',
'#token_types' => 'all',
'#click_insert' => FALSE,
'#show_restricted' => TRUE,
];

return drupal_render($output);
}
}

Expand Down
30 changes: 16 additions & 14 deletions token.pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,35 @@ function theme_token_tree_link($variables) {
*
* @ingroup themeable
*/
function theme_tree_table($variables) {
function template_preprocess_tree_table(&$variables) {
foreach ($variables['rows'] as &$row) {
$row += array('class' => array());
if (!empty($row['parent'])) {
$row['class'][] = 'child-of-' . $row['parent'];
unset($row['parent']);
}
}
$attached['#attached']['library'][] = 'token/token';
$variables['#attached']['library'][] = 'token/token';
if (!empty($variables['rows'])) {
$attached['#attached']['library'][] = 'token/jquery.treeTable';
$variables['#attached']['library'][] = 'token/jquery.treeTable';
}
drupal_render($attached);
// ToDo: Use render arrays. See https://drupal.org/node/2195739
return _theme('table', $variables);

$variables['content'] = [
'#theme' => 'table',
'#headers' => $variables['headers'],
'#rows' => $variables['rows'],
];

}

/**
* Provide a 'tree' display of nested tokens.
*
* Default template: token_tree.twig.html
*
* @ingroup themeable
*/
function theme_token_tree($variables) {
if (!empty($variables['dialog'])) {
return _theme('token_tree_link', $variables);
}
function template_preprocess_token_tree(&$variables) {

$token_types = $variables['token_types'];
$info = token_get_info();
Expand Down Expand Up @@ -137,7 +140,7 @@ function theme_token_tree($variables) {
}

$element += array(
'#theme' => 'tree_table',
'#theme' => 'table',
'#header' => array(
t('Name'),
t('Token'),
Expand All @@ -157,9 +160,8 @@ function theme_token_tree($variables) {
$element['#attributes']['class'][] = 'token-click-insert';
}

$output = drupal_render($element);
token_render_cache_set($output, $element);
return $output;
$variables['content'] = $element;

}

/**
Expand Down