diff --git a/core/includes/theme.inc b/core/includes/theme.inc index c19db2646d0..228065ac343 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2213,20 +2213,34 @@ function theme_table($variables) { } /** - * Returns HTML for a sort icon. + * Prepares variables for tablesort indicator templates. * - * @param $variables + * Default template: tablesort-indicator.html.twig. + * + * @param array $variables * An associative array containing: - * - style: Set to either 'asc' or 'desc', this determines which icon to - * show. + * - style: Set to either 'asc' or 'desc'. This determines which icon to show. */ -function theme_tablesort_indicator($variables) { - if ($variables['style'] == "asc") { - return theme('image', array('uri' => 'core/misc/arrow-asc.png', 'width' => 13, 'height' => 13, 'alt' => t('sort ascending'), 'title' => t('sort ascending'))); +function template_preprocess_tablesort_indicator(&$variables) { + // Provide the image attributes for an ascending or descending image. + if ($variables['style'] == 'asc') { + $variables['uri'] = 'core/misc/arrow-asc.png'; + $alt_title = t('sort ascending'); } else { - return theme('image', array('uri' => 'core/misc/arrow-desc.png', 'width' => 13, 'height' => 13, 'alt' => t('sort descending'), 'title' => t('sort descending'))); + $variables['uri'] = 'core/misc/arrow-desc.png'; + $alt_title = t('sort descending'); } + + // Add the image element. + $variables['image'] = array( + '#theme' => 'image', + '#uri' => $variables['uri'], + '#width' => 13, + '#height' => 13, + '#alt' => $alt_title, + '#title' => $alt_title, + ); } /** @@ -3141,6 +3155,7 @@ function drupal_common_theme() { ), 'tablesort_indicator' => array( 'variables' => array('style' => NULL), + 'template' => 'tablesort-indicator', ), 'mark' => array( 'variables' => array('mark_type' => MARK_NEW), diff --git a/core/modules/system/templates/tablesort-indicator.html.twig b/core/modules/system/templates/tablesort-indicator.html.twig new file mode 100644 index 00000000000..f5e9c922ac9 --- /dev/null +++ b/core/modules/system/templates/tablesort-indicator.html.twig @@ -0,0 +1,19 @@ +{# +/** + * @file + * Default theme implementation for displaying a tablesort indicator. + * + * Available variables: + * - image: A renderable image element. + * - style: Either 'asc' or 'desc', indicating the sorting direction. + * - uri: URI to ascending or descending image. + * + * @see template_preprocess() + * @see template_preprocess_tablesort_indicator() + * + * @ingroup themeable + */ +#} +{% spaceless %} + {{ image }} +{% endspaceless %}