From 2729f1c2f0ae6aa790edf1a8be70a74fae04934c Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Fri, 11 Sep 2009 06:48:03 +0000 Subject: [PATCH] - Patch #569362 by scor, effulgentsia, catch: add attributes and title_attributes() variables for tpl files so that RDFa and Microformats can be implemented. --- includes/theme.inc | 8 ++++++++ modules/block/block.tpl.php | 4 ++-- modules/comment/comment-wrapper.tpl.php | 2 +- modules/comment/comment.tpl.php | 4 ++-- modules/field/field.module | 16 ++++++++++++++++ modules/field/theme/field.tpl.php | 6 +++--- modules/node/node.tpl.php | 4 ++-- themes/garland/block.tpl.php | 4 ++-- themes/garland/comment.tpl.php | 4 ++-- themes/garland/node.tpl.php | 4 ++-- 10 files changed, 40 insertions(+), 16 deletions(-) diff --git a/includes/theme.inc b/includes/theme.inc index 3ac1dc90f378..352706effd63 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -2042,6 +2042,10 @@ function template_preprocess(&$variables, $hook) { // Initialize html class attribute for the current hook. $variables['classes_array'] = array($hook); + // Initialize attributes for the top-level template entity and its title. + $variables['attributes_array'] = array(); + $variables['title_attributes_array'] = array(); + // Set default variables that depend on the database. $variables['is_admin'] = FALSE; $variables['is_front'] = FALSE; @@ -2066,6 +2070,10 @@ function template_preprocess(&$variables, $hook) { function template_process(&$variables, $hook) { // Flatten out classes. $variables['classes'] = implode(' ', $variables['classes_array']); + + // Flatten out attributes and title_attributes. + $variables['attributes'] = drupal_attributes($variables['attributes_array']); + $variables['title_attributes'] = drupal_attributes($variables['title_attributes_array']); } /** diff --git a/modules/block/block.tpl.php b/modules/block/block.tpl.php index 77b1fa938394..961cb01b01df 100644 --- a/modules/block/block.tpl.php +++ b/modules/block/block.tpl.php @@ -35,9 +35,9 @@ * @see template_process() */ ?> -<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>"> +<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>> <?php if ($block->subject): ?> - <h2><?php print $block->subject ?></h2> + <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2> <?php endif;?> <div class="content"> diff --git a/modules/comment/comment-wrapper.tpl.php b/modules/comment/comment-wrapper.tpl.php index aabf3850fa8c..1d1e1fe9b235 100644 --- a/modules/comment/comment-wrapper.tpl.php +++ b/modules/comment/comment-wrapper.tpl.php @@ -30,7 +30,7 @@ * @see theme_comment_wrapper() */ ?> -<div id="comments" class="<?php print $classes; ?>"> +<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>> <?php if ($node->type != 'forum'): ?> <h2 class="comments"><?php print t('Comments'); ?></h2> <?php endif; ?> diff --git a/modules/comment/comment.tpl.php b/modules/comment/comment.tpl.php index cae102f85a1b..e777855906e8 100644 --- a/modules/comment/comment.tpl.php +++ b/modules/comment/comment.tpl.php @@ -44,14 +44,14 @@ * @see theme_comment() */ ?> -<div class="<?php print $classes; ?> clearfix"> +<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php print $picture ?> <?php if ($new): ?> <span class="new"><?php print $new ?></span> <?php endif; ?> - <h3><?php print $title ?></h3> + <h3<?php print $title_attributes; ?>><?php print $title ?></h3> <div class="submitted"> <?php diff --git a/modules/field/field.module b/modules/field/field.module index 487ea359577e..75dc3d43111f 100644 --- a/modules/field/field.module +++ b/modules/field/field.module @@ -756,8 +756,24 @@ function template_preprocess_field(&$variables) { ), ); $variables = array_merge($variables, $additions); + + // Initialize attributes for each item. + foreach ($variables['items'] as $delta => $item) { + $variables['item_attributes_array'][$delta] = array(); + } } +/** + * Theme process function for field.tpl.php. + * + * @see field.tpl.php + */ +function template_process_field(&$variables) { + // Flatten out attributes for each item. + foreach ($variables['items'] as $delta => $item) { + $variables['item_attributes'][$delta] = drupal_attributes($variables['item_attributes_array'][$delta]); + } +} /** * @} End of "defgroup field" */ diff --git a/modules/field/theme/field.tpl.php b/modules/field/theme/field.tpl.php index 9018f45b5010..312c4b8443c5 100644 --- a/modules/field/theme/field.tpl.php +++ b/modules/field/theme/field.tpl.php @@ -39,13 +39,13 @@ */ ?> <?php if ($items) : ?> - <div class="field <?php print $classes; ?> clearfix"> + <div class="field <?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php if (!$label_hidden) : ?> - <div class="field-label"><?php print $label ?>: </div> + <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>: </div> <?php endif; ?> <div class="field-items"> <?php foreach ($items as $delta => $item) : ?> - <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"><?php print render($item); ?></div> + <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div> <?php endforeach; ?> </div> </div> diff --git a/modules/node/node.tpl.php b/modules/node/node.tpl.php index c3aa2353970f..1bc4c2c6e5eb 100644 --- a/modules/node/node.tpl.php +++ b/modules/node/node.tpl.php @@ -70,12 +70,12 @@ * @see template_process() */ ?> -<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"> +<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php print $user_picture; ?> <?php if (!$page): ?> - <h2><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2> + <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2> <?php endif; ?> <?php if ($display_submitted || !empty($content['links']['terms'])): ?> diff --git a/themes/garland/block.tpl.php b/themes/garland/block.tpl.php index 50a79d363424..4d9e443e2c8b 100644 --- a/themes/garland/block.tpl.php +++ b/themes/garland/block.tpl.php @@ -1,10 +1,10 @@ <?php // $Id$ ?> -<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?> clearfix"> +<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php if (!empty($block->subject)): ?> - <h2 class="title"><?php print $block->subject ?></h2> + <h2 class="title"<?php print $title_attributes; ?>><?php print $block->subject ?></h2> <?php endif;?> <div class="content"><?php print $content ?></div> diff --git a/themes/garland/comment.tpl.php b/themes/garland/comment.tpl.php index d664d236073c..9a8959cc5617 100644 --- a/themes/garland/comment.tpl.php +++ b/themes/garland/comment.tpl.php @@ -1,7 +1,7 @@ <?php // $Id$ ?> -<div class="<?php print $classes . ' ' . $zebra; ?>"> +<div class="<?php print $classes . ' ' . $zebra; ?>"<?php print $attributes; ?>> <div class="clearfix"> @@ -13,7 +13,7 @@ <?php print $picture ?> - <h3><?php print $title ?></h3> + <h3<?php print $title_attributes; ?>><?php print $title ?></h3> <div class="content"> <?php hide($content['links']); print render($content); ?> diff --git a/themes/garland/node.tpl.php b/themes/garland/node.tpl.php index 9895917d17b6..01038e21b2f7 100644 --- a/themes/garland/node.tpl.php +++ b/themes/garland/node.tpl.php @@ -1,12 +1,12 @@ <?php // $Id$ ?> -<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?>"> +<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>> <?php print $user_picture; ?> <?php if (!$page): ?> - <h2><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2> + <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2> <?php endif; ?> <?php if ($display_submitted): ?> -- GitLab