Mixing old and new links styles
Last modified: June 9, 2006 - 12:59
Because this is a major change and many contributed modules haven't made this update yet, it is getting to be difficult to function in cvs. I made a patch to theme.inc that will accept links in both the old and new format so I can keep operating without errors. I haven't submitted this patch as an 'official' patch because I don't know if this is desirable for core, but it may be useful to others who are trying to use a variety of contributed modules in cvs without the need to patch them all.
I see that I can't attach a file to a book page, so I am just pasting my changed code for the theme_links function.
<?php
/**
* Return a themed set of links.
*
* @param $links
* A keyed array of links to be themed.
* @param $delimiter
* A string used to separate the links.
* @return
* A string containing the themed links.
*/
function theme_links($links, $delimiter = ' | ') {
$output = array();
if (is_array($links)) {
foreach ($links as $key => $link) {
// trap old-format links and return them the old way
if (!is_array($link)) {
$output[] = $link;
} else {
//Automatically add a class to each link and convert all _ to - for XHTML compliance
if (isset($link['#attributes']) && isset($link['#attributes']['class'])) {
$link['#attributes']['class'] .= ' '. str_replace('_', '-', $key);
}
else {
$link['#attributes']['class'] = str_replace('_', '-', $key);
}
if ($link['#href']) {
$output[] = l($link['#title'], $link['#href'], $link['#attributes'], $link['#query'], $link['#fragment']);
}
else if ($link['#title']) {
//Some links are actually not links, but we wrap these in <span> for adding title and class attributes
$output[] = '<span'. drupal_attributes($link['#attributes']) .'>'. $link['#title'] .'</span>';
}
}
}
}
return implode($delimiter, $output);
}
?>