From 3c51cdc7dfc76d1faff98382aaec4f1d64544273 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Fri, 7 Nov 2014 13:42:04 +1100 Subject: [PATCH 1/2] Fix token tree theme --- templates/token_tree.html.twig | 17 +++++++++++++++++ token.module | 15 ++++++++++----- token.pages.inc | 9 +++++---- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 templates/token_tree.html.twig diff --git a/templates/token_tree.html.twig b/templates/token_tree.html.twig new file mode 100644 index 0000000..1daedfc --- /dev/null +++ b/templates/token_tree.html.twig @@ -0,0 +1,17 @@ +{# +/** + * @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 + */ +#} + + {{ element }} + diff --git a/token.module b/token.module index 6bc8ab1..e7f800b 100644 --- a/token.module +++ b/token.module @@ -35,11 +35,16 @@ function token_help($route_name, RouteMatchInterface $route_match) { // return a TRUE value if this is not actually the help page. return TRUE; } - $output = '
'; - $output .= '
' . t('List of the currently available tokens on this site') . '
'; - // ToDo: Use render arrays. See https://drupal.org/node/2195739 - $output .= '
' . _theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '
'; - $output .= '
'; + $output = []; + $output['#prefix'] = t('List of the currently available tokens on this site'); + + $output[] = [ + '#theme' => 'token_tree', + '#token_types' => 'all', + '#click_insert' => FALSE, + '#show_restricted' => TRUE, + ]; + return $output; } } diff --git a/token.pages.inc b/token.pages.inc index 22711c9..ae7cad6 100644 --- a/token.pages.inc +++ b/token.pages.inc @@ -76,9 +76,11 @@ function theme_tree_table($variables) { /** * Provide a 'tree' display of nested tokens. * + * Default template: token_tree.twig.html + * * @ingroup themeable */ -function theme_token_tree($variables) { +function template_preprocess_token_tree(&$variables) { if (!empty($variables['dialog'])) { return _theme('token_tree_link', $variables); } @@ -157,9 +159,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['element'] = $element; + } /** From 7e496d458cd4b6597da63c01e0745ebe5d0a4cb3 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Fri, 7 Nov 2014 16:00:42 +1100 Subject: [PATCH 2/2] Move theming functions to preprocess hooks --- ...en_tree.html.twig => token-tree.html.twig} | 3 ++- templates/tree-table.html.twig | 15 ++++++++++++ token.module | 4 ++-- token.pages.inc | 23 ++++++++++--------- 4 files changed, 31 insertions(+), 14 deletions(-) rename templates/{token_tree.html.twig => token-tree.html.twig} (94%) create mode 100644 templates/tree-table.html.twig diff --git a/templates/token_tree.html.twig b/templates/token-tree.html.twig similarity index 94% rename from templates/token_tree.html.twig rename to templates/token-tree.html.twig index 1daedfc..6fb86e8 100644 --- a/templates/token_tree.html.twig +++ b/templates/token-tree.html.twig @@ -12,6 +12,7 @@ * @ingroup themeable */ #} + - {{ element }} + {{ content }} diff --git a/templates/tree-table.html.twig b/templates/tree-table.html.twig new file mode 100644 index 0000000..ec5b4fa --- /dev/null +++ b/templates/tree-table.html.twig @@ -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 }} diff --git a/token.module b/token.module index e7f800b..224ebbb 100644 --- a/token.module +++ b/token.module @@ -38,14 +38,14 @@ function token_help($route_name, RouteMatchInterface $route_match) { $output = []; $output['#prefix'] = t('List of the currently available tokens on this site'); - $output[] = [ + $output['content'] = [ '#theme' => 'token_tree', '#token_types' => 'all', '#click_insert' => FALSE, '#show_restricted' => TRUE, ]; - return $output; + return drupal_render($output); } } diff --git a/token.pages.inc b/token.pages.inc index ae7cad6..2bbb28c 100644 --- a/token.pages.inc +++ b/token.pages.inc @@ -56,7 +56,7 @@ 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'])) { @@ -64,13 +64,17 @@ function theme_tree_table($variables) { 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'], + ]; + } /** @@ -81,9 +85,6 @@ function theme_tree_table($variables) { * @ingroup themeable */ function template_preprocess_token_tree(&$variables) { - if (!empty($variables['dialog'])) { - return _theme('token_tree_link', $variables); - } $token_types = $variables['token_types']; $info = token_get_info(); @@ -139,7 +140,7 @@ function template_preprocess_token_tree(&$variables) { } $element += array( - '#theme' => 'tree_table', + '#theme' => 'table', '#header' => array( t('Name'), t('Token'), @@ -159,7 +160,7 @@ function template_preprocess_token_tree(&$variables) { $element['#attributes']['class'][] = 'token-click-insert'; } - $variables['element'] = $element; + $variables['content'] = $element; }