Commit babb2b71 authored by catch's avatar catch

Issue #1825090 by thedavidmeister, Cottser: Remove theme_html_tag() from the theme system.

parent a4484238
......@@ -329,7 +329,7 @@ function drupal_get_breadcrumb() {
* @return
* An array of all stored HEAD elements.
*
* @see theme_html_tag()
* @see drupal_pre_render_html_tag()
*/
function drupal_add_html_head($data = NULL, $key = NULL) {
$stored_head = &drupal_static(__FUNCTION__);
......@@ -4463,6 +4463,44 @@ function drupal_pre_render_conditional_comments($elements) {
return $elements;
}
/**
* Pre-render callback: Renders a generic HTML tag with attributes into #markup.
*
* @param array $element
* An associative array containing:
* - #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) An array of HTML attributes to apply to the
* tag.
* - #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 drupal_pre_render_html_tag($element) {
$attributes = isset($element['#attributes']) ? new Attribute($element['#attributes']) : '';
if (!isset($element['#value'])) {
$markup = '<' . $element['#tag'] . $attributes . " />\n";
}
else {
$markup = '<' . $element['#tag'] . $attributes . '>';
if (isset($element['#value_prefix'])) {
$markup .= $element['#value_prefix'];
}
$markup .= $element['#value'];
if (isset($element['#value_suffix'])) {
$markup .= $element['#value_suffix'];
}
$markup .= '</' . $element['#tag'] . ">\n";
}
$element['#markup'] = $markup;
return $element;
}
/**
* Pre-render callback: Renders a link into #markup.
*
......
......@@ -2418,45 +2418,6 @@ function theme_feed_icon($variables) {
}
}
/**
* Returns HTML for a generic HTML tag with attributes.
*
* @param $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:
* - 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) An array of HTML attributes to apply to the
* tag.
* - #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) {
$element = $variables['element'];
$attributes = isset($element['#attributes']) ? new Attribute($element['#attributes']) : '';
if (!isset($element['#value'])) {
return '<' . $element['#tag'] . $attributes . " />\n";
}
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 .= '</' . $element['#tag'] . ">\n";
return $output;
}
}
/**
* Returns HTML for a "more" link, like those used in blocks.
*
......@@ -3230,9 +3191,6 @@ function drupal_common_theme() {
'indentation' => array(
'variables' => array('size' => 1),
),
'html_tag' => array(
'render element' => 'element',
),
// From theme.maintenance.inc.
'maintenance_page' => array(
'variables' => array('content' => NULL, 'show_messages' => TRUE),
......
......@@ -51,7 +51,7 @@ function config_admin_sync_form(array &$form, array &$form_state, StorageInterfa
// @todo A table caption would be more appropriate, but does not have the
// visual importance of a heading.
$form[$config_change_type]['heading'] = array(
'#theme' => 'html_tag__h3',
'#type' => 'html_tag',
'#tag' => 'h3',
);
switch ($config_change_type) {
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Common\HtmlTagTest.
*/
namespace Drupal\system\Tests\Common;
use Drupal\simpletest\WebTestBase;
/**
* Tests for #type 'html_tag'.
*/
class HtmlTagTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Render HTML tags',
'description' => 'Tests rendering of html_tag type renderable arrays.',
'group' => 'Common',
);
}
/**
* Tests #type 'html_tag'.
*/
function testHtmlTag() {
// Test auto-closure meta tag generation.
$tag = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'description',
'content' => 'Drupal test',
),
);
$this->assertEqual('<meta name="description" content="Drupal test" />' . "\n", drupal_render($tag), 'Test auto-closure meta tag generation.');
// Test title tag generation.
$tag = array(
'#type' => 'html_tag',
'#tag' => 'title',
'#value' => 'title test',
);
$this->assertEqual('<title>title test</title>' . "\n", drupal_render($tag), 'Test title tag generation.');
}
}
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\HtmlTagUnitTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\UnitTestBase;
/**
* Unit tests for theme_html_tag().
*/
class HtmlTagUnitTest extends UnitTestBase {
public static function getInfo() {
return array(
'name' => 'Theme HTML Tag',
'description' => 'Tests theme_html_tag() built-in theme functions.',
'group' => 'Theme',
);
}
/**
* Test function theme_html_tag()
*/
function testThemeHtmlTag() {
// Test auto-closure meta tag generation
$tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test'));
$this->assertEqual('<meta name="description" content="Drupal test" />'."\n", theme_html_tag($tag), 'Test auto-closure meta tag generation.');
// Test title tag generation
$tag['element'] = array('#tag' => 'title', '#value' => 'title test');
$this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), 'Test title tag generation.');
}
}
......@@ -276,8 +276,7 @@ function system_element_info() {
'#error' => NULL,
);
$types['html_tag'] = array(
'#theme' => 'html_tag',
'#pre_render' => array('drupal_pre_render_conditional_comments'),
'#pre_render' => array('drupal_pre_render_conditional_comments', 'drupal_pre_render_html_tag'),
'#attributes' => array(),
'#value' => NULL,
);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment