diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8d527df..c659646 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2427,9 +2427,11 @@ function theme_feed_icon($variables) { } /** - * Returns HTML for a generic HTML tag with attributes. + * Prepares variables for the HTML tag templates. * - * @param $variables + * Default template: html-tag.html.twig. + * + * @param array $variables * An associative array containing: * - element: An associative array describing the tag: * - #tag: The tag name to output. Typical tags added to the HTML HEAD: @@ -2438,30 +2440,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 +3210,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..57996cd --- /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 %} + <{{ tag }}{{ attributes }}> + {% if value_prefix %} + {{ value_prefix }} + {% endif %} + {{ value }} + {% if value_suffix %} + {{ value_suffix }} + {% endif %} + +{% else %} + <{{ tag }}{{ attributes }}/> +{% endif %}