/** * * @param MenuItem $menuItem * @param integer $depth The depth each child should render * @return array */ public function getItemAttributes(MenuItem $item) { // if we don't have access or this item is marked to not be shown if (!$item->shouldBeRendered()) { return; } $depth = $item->getLevel(); // explode the class string into an array of classes $class = ($item->getAttribute('class')) ? explode(' ', $item->getAttribute('class')) : array(); if ($item->getIsCurrent()) { $class[] = 'current'; } elseif ($item->getIsCurrentAncestor($depth)) { $class[] = 'current_ancestor'; } if ($item->actsLikeFirst()) { $class[] = 'first'; } if ($item->actsLikeLast()) { $class[] = 'last'; } // retrieve the attributes and put the final class string back on it $attributes = $item->getAttributes(); if (!empty($class)) { $attributes['class'] = implode(' ', $class); } return $attributes; }