Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.573
diff -u -p -r1.573 theme.inc
--- includes/theme.inc 7 Feb 2010 09:11:28 -0000 1.573
+++ includes/theme.inc 13 Feb 2010 08:42:05 -0000
@@ -1948,12 +1948,15 @@ function theme_feed_icon($variables) {
* Generate the output for a generic HTML tag with attributes.
*
* This theme function should be used for tags appearing in the HTML HEAD of a
- * document (specified via the #tag property in the passed $element):
+ * document (specified via the #tag property in the passed $element). While it
+ * can also be used for tags appearing in the HTML BODY, this should be very
+ * rare, since more specific theme functions should be used for anything
+ * visible.
*
* @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:
+ * - #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.
@@ -1964,26 +1967,36 @@ function theme_feed_icon($variables) {
* wrapper prefix.
* - #value_suffix: (optional) A string to append to #value, e.g. a CDATA
* wrapper suffix.
+ * - #minimized_if_empty: (optional) Can be set to TRUE or FALSE to force
+ * the rendered output to use the minimized tag syntax (e.g.,
+ * "") or not (e.g., "") if the tag
+ * content is empty. If not specified, this defaults to the XHTML
+ * guidelines (http://www.w3.org/TR/xhtml1/#guidelines).
*
* @ingroup themeable
*/
function theme_html_tag($variables) {
+ // http://www.w3.org/TR/xhtml1/dtds.html
+ static $tags_with_empty_content_model = array('area', 'base', 'basefont', 'br', 'col', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param');
$element = $variables['element'];
- if (!isset($element['#value'])) {
- return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n";
- }
- else {
- $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
+ $minimized_if_empty = isset($element['#minimized_if_empty']) ? $element['#minimized_if_empty'] : in_array(strtolower($element['#tag']), $tags_with_empty_content_model);
+ $content = '';
+ if (isset($element['#value'])) {
if (isset($element['#value_prefix'])) {
- $output .= $element['#value_prefix'];
+ $content .= $element['#value_prefix'];
}
- $output .= $element['#value'];
+ $content .= $element['#value'];
if (isset($element['#value_suffix'])) {
- $output .= $element['#value_suffix'];
+ $content .= $element['#value_suffix'];
}
- $output .= '' . $element['#tag'] . ">\n";
- return $output;
}
+ if ($minimized_if_empty && !strlen($content)) {
+ $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n";
+ }
+ else {
+ $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>' . $content . '' . $element['#tag'] . ">\n";
+ }
+ return $output;
}
/**