From ebb5e3644ec468d1ae8c2b9bff2eff7afa3519c2 Mon Sep 17 00:00:00 2001 From: "mamoun.othman" Date: Tue, 19 Mar 2013 17:47:25 +0200 Subject: [PATCH] convert html-tag theme to twig template, merging with core. --- core/includes/theme.inc | 33 +++++++++----------- core/modules/system/templates/html-tag.html.twig | 36 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 core/modules/system/templates/html-tag.html.twig diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8d527df..db76a1e 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2427,7 +2427,7 @@ function theme_feed_icon($variables) { } /** - * Returns HTML for a generic HTML tag with attributes. + * Preprocess variables for html-tag.html.twig * * @param $variables * An associative array containing: @@ -2438,30 +2438,26 @@ function theme_feed_icon($variables) { * - script: To load JavaScript. * - #attributes: (optional) An array of HTML attributes to apply to the * tag. - * - #value: (optional) A string containing tag content, such as inline - * CSS. + * - #value: (optional) A string containing tag content, such as inline CSS. * - #value_prefix: (optional) A string to prepend to #value, e.g. a CDATA * wrapper prefix. * - #value_suffix: (optional) A string to append to #value, e.g. a CDATA * wrapper suffix. */ -function theme_html_tag($variables) { +function template_preprocess_html_tag(&$variables) { $element = $variables['element']; - $attributes = isset($element['#attributes']) ? new Attribute($element['#attributes']) : ''; - if (!isset($element['#value'])) { - return '<' . $element['#tag'] . $attributes . " />\n"; + $variables['attributes'] = isset($element['#attributes']) ? new Attribute($element['#attributes']) : new Attribute(array()); + if (isset($element['#value'])) { + $variables['value'] = $element['#value']; } - else { - $output = '<' . $element['#tag'] . $attributes . '>'; - if (isset($element['#value_prefix'])) { - $output .= $element['#value_prefix']; - } - $output .= $element['#value']; - if (isset($element['#value_suffix'])) { - $output .= $element['#value_suffix']; - } - $output .= '\n"; - return $output; + if (isset($element['#tag'])) { + $variables['tag'] = $element['#tag']; + } + if (isset($element['#value_prefix'])) { + $variables['value_prefix'] = $element['#value_prefix']; + } + if (isset($element['#value_prefix'])) { + $variables['value_suffix'] = $element['#value_suffix']; } } @@ -3212,6 +3208,7 @@ function drupal_common_theme() { ), 'html_tag' => array( 'render element' => 'element', + 'template' => 'html-tag', ), // From theme.maintenance.inc. 'maintenance_page' => array( diff --git a/core/modules/system/templates/html-tag.html.twig b/core/modules/system/templates/html-tag.html.twig new file mode 100644 index 0000000..42f1536 --- /dev/null +++ b/core/modules/system/templates/html-tag.html.twig @@ -0,0 +1,36 @@ +{# +/** + * Default theme implementation for a generic HTML tag with attributes. + * + * Available variables: + * - tag: The tag name to output. Typical tags added to the HTML HEAD: + * - meta: To provide meta information, such as a page refresh. + * - link: To refer to stylesheets and other contextual information. + * - script: To load JavaScript. + * - attributes: (optional) Remaining HTML attributes to apply to the tag. + * - value: (optional) The tag content, such as inline CSS. + * - value_prefix: (optional) Prepend this to value, e.g. a CDATA wrapper + * prefix. + * - value_suffix: (optional) Append this to value, e.g. a CDATA wrapper + * suffix. + * + * @see template_preprocess() + * @see template_preprocess_html_tag() + * + * @ingroup themeable + */ + @todo: delete this file once http://drupal.org/node/1825090 is resolved. +#} +{% if value is defined %} + <{{ tag }} class="{{ attributes.class }}"{{ attributes }}> + {% if value_prefix is defined %} + {{ value_prefix }} + {% endif %} + {{ value }} + {% if value_suffix is defined %} + {{ value_suffix }} + {% endif %} + +{% else %} + <{{ tag }} class="{{ attributes.class }}"{{ attributes }}/> +{% endif %} -- 1.7.10.4