From 245d83cb84124af7fd595e0a552a6ba782720d2e Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Tue, 25 Aug 2009 15:39:13 +0000 Subject: [PATCH] #364219 follow-up by TheRec: Fix invocations of theme_links() via Drupal's rendering API. --- includes/common.inc | 2 +- includes/theme.inc | 20 ++++++++++++-------- modules/system/page.tpl.php | 4 ++-- themes/garland/template.php | 36 ++++++++++++++++++++++++++++++------ 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 6e79e66734b..05a96512d08 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4257,7 +4257,7 @@ function drupal_common_theme() { 'arguments' => array('display' => NULL), ), 'links' => array( - 'arguments' => array('links' => NULL, 'attributes' => array('class' => array('links'))), + 'arguments' => array('links' => NULL, 'attributes' => array('class' => array('links')), 'heading' => array()), ), 'image' => array( 'arguments' => array('path' => NULL, 'alt' => '', 'title' => '', 'attributes' => array(), 'getsize' => TRUE), diff --git a/includes/theme.inc b/includes/theme.inc index fc7216f8338..e3b19769770 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1383,11 +1383,13 @@ function theme_status_messages($display = NULL) { * - href: the link URL. If omitted, the 'title' is shown as a plain text item in the links list. * - html: (optional) set this to TRUE if 'title' is HTML so it will be escaped. * Array items are passed on to the l() function's $options parameter when creating the link. + * @param $attributes + * A keyed array of attributes. * @param $heading * An optional keyed array for a heading to precede the links: * - text: the heading text * - level: the heading level (e.g. 'h2', 'h3') - * - class: (optional) space-separated classes for the heading + * - class: (optional) an array of the CSS classes for the heading * Headings should be used on navigation menus and any list of links that * consistently appears on multiple pages. To make the heading invisible * use class => 'element-invisible'. Do not use 'display:none', which @@ -1395,22 +1397,24 @@ function theme_status_messages($display = NULL) { * screen-reader and keyboard only users to navigate to or skip the links. * See http://juicystudio.com/article/screen-readers-display-none.php * and http://www.w3.org/TR/WCAG-TECHS/H42.html for more information. - * @param $attributes - * A keyed array of attributes. * @return * A string containing an unordered list of links. */ -function theme_links($links, $heading = array(), $attributes = array('class' => array('links'))) { +function theme_links($links, $attributes = array('class' => array('links')), $heading = array()) { global $language; $output = ''; if (count($links) > 0) { $output = ''; + + // Treat the heading first if it is present to prepend it to the + // list of links. if (!empty($heading['text']) && !empty($heading['level'])) { - $output .= '<' . $heading['level'] . (!empty($heading['class']) ? - drupal_attributes(array('class' => $heading['class'])) : '') . '>'; - $output .= check_plain($heading['text']); - $output .= ''; + $output .= '<' . $heading['level']; + if (!empty($heading['class'])) { + $output .= ' ' . drupal_attributes(array('class' => $heading['class'])); + } + $output .= '>' . check_plain($heading['text']) . ''; } $output .= ''; diff --git a/modules/system/page.tpl.php b/modules/system/page.tpl.php index eb449a619f2..5f0a96fdbe9 100644 --- a/modules/system/page.tpl.php +++ b/modules/system/page.tpl.php @@ -156,7 +156,7 @@ @@ -195,7 +195,7 @@ diff --git a/themes/garland/template.php b/themes/garland/template.php index 4928977567e..c8b170d9ecf 100644 --- a/themes/garland/template.php +++ b/themes/garland/template.php @@ -19,12 +19,36 @@ function garland_breadcrumb($breadcrumb) { */ function garland_preprocess_page(&$vars) { $vars['tabs2'] = menu_secondary_local_tasks(); - $vars['primary_nav'] = isset($vars['main_menu']) ? theme('links', $vars['main_menu'], array( - 'text' => t('Main menu'), 'level' => 'h2', 'class' => array('element-invisible'), - ), array('class' => array('links', 'main-menu'))) : FALSE; - $vars['secondary_nav'] = isset($vars['secondary_menu']) ? theme('links', $vars['secondary_menu'], array( - 'text' => t('Secondary menu'), 'level' => 'h2', 'class' => array('element-invisible'), - ), array('class' => array('links', 'secondary-menu'))) : FALSE; + if (isset($vars['main_menu'])) { + $vars['primary_nav'] = theme('links', $vars['main_menu'], + array( + 'class' => array('links', 'main-menu'), + ), + array( + 'text' => t('Main menu'), + 'level' => 'h2', + 'class' => array('element-invisible'), + ) + ); + } + else { + $vars['primary_nav'] = FALSE; + } + if (isset($vars['secondary_menu'])) { + $vars['secondary_nav'] = theme('links', $vars['secondary_menu'], + array( + 'class' => array('links', 'secondary-menu'), + ), + array( + 'text' => t('Secondary menu'), + 'level' => 'h2', + 'class' => array('element-invisible'), + ) + ); + } + else { + $vars['secondary_nav'] = FALSE; + } $vars['ie_styles'] = garland_get_ie_styles(); // Prepare header