1

I'm trying to override the way that menu items are displayed. I have the following function :

 function newtheme_item_list($items = array(),$title=NULL,$type='ul',$attributes=NULL)
 {
 $positions = array("","second","third","forth");
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
foreach ($items as $item_key=>$item) {
  $attributes = array();
  $children = array();
  if (is_array($item)) {
    foreach ($item as $key => $value) {
      if ($key == 'data') {
        $data = $value;
      }
      elseif ($key == 'children') {
        $children = $value;
      }
      else {
        $attributes[$key] = $value;
      }
    }
  }
  else {
    $data = $item;
  }

  if (count($children) > 0) {
    $data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list
  }
  if ($item_key > 0)
  {
    $attributes['class'] = ' nav_separator '.$positions[$item_key].'-nav'; 
  }
  if($item_key == 0) {
    $attributes['class'] = 'first-nav';
  } 
  elseif($item_key == count($items)-1){

    $attributes['class'] = ' last-nav';
  }

  $output .= '<li' . drupal_attributes($attributes) . '>'. $data .'</li>';
}
$output .= "</$type>";
}
$output .= '</div>';
return $output;


}

In the page.inc.php i have the line:

print theme('links', array('links' => menu_navigation_links('main-menu'),'attributes' => array('class'=> array('links', 'site-menu')))); 

This it should add some different classes to my menu but instead i get this error:

Recoverable fatal error: Argument 1 passed to drupal_attributes() must be an array, null given, called in D:\EasyPHP-5.3.5.0\www\drupal\themes\newtheme\template.php on line 12 and defined in drupal_attributes() (line 2301 of D:\EasyPHP-5.3.5.0\www\drupal\includes\common.inc).
2
  • Is this drupal 6 or 7? Looks like Drupal 6 code.
    – googletorp
    Commented Oct 15, 2012 at 10:50
  • The version is Drupal 7.x
    – Vlasin
    Commented Oct 15, 2012 at 10:52

1 Answer 1

2

Your function signature is off, it should be like this:

function newtheme_item_list($variables) {
  $items = $variables['items'];
  $title = $variables['title'];
  $type = $variables['type'];
  $attributes = $variables['attributes'];
  ..
}

You should check the docs, when creating theme functions.

4
  • It seems that is not working !I got rid of that error but the classes are not changed .
    – Vlasin
    Commented Oct 15, 2012 at 11:00
  • @GigiBecali This approach is not really good for changing classes on menu items. The reason is that it will effect all item lists on your site which probably isn't what you wanted.
    – googletorp
    Commented Oct 15, 2012 at 11:03
  • could you please recommend something ?
    – Vlasin
    Commented Oct 15, 2012 at 11:04
  • @GigiBecali You should take a look at theme_menu_link
    – googletorp
    Commented Oct 15, 2012 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.