lib: Support setting CSS class for li on navigation items

refs #5543
This commit is contained in:
Eric Lippmann 2015-09-28 16:39:28 +02:00
parent a408636923
commit ed6da19876
2 changed files with 38 additions and 4 deletions

View File

@ -36,6 +36,13 @@ class NavigationItem implements IteratorAggregate
*/
protected $active;
/**
* The CSS class used for the outer li element
*
* @var string
*/
protected $cssClass;
/**
* This item's priority
*
@ -200,6 +207,29 @@ class NavigationItem implements IteratorAggregate
return $this;
}
/**
* Get the CSS class used for the outer li element
*
* @return string
*/
public function getCssClass()
{
return $this->cssClass;
}
/**
* Set the CSS class to use for the outer li element
*
* @param string $class
*
* @return $this
*/
public function setCssClass($class)
{
$this->cssClass = (string) $class;
return $this;
}
/**
* Return this item's priority
*

View File

@ -304,10 +304,10 @@ class NavigationRenderer implements RecursiveIterator, NavigationRendererInterfa
*/
public function beginItemMarkup(NavigationItem $item)
{
$cssClass = array(static::CSS_CLASS_ITEM);
$cssClasses = array(static::CSS_CLASS_ITEM);
if ($item->hasChildren() && $item->getChildren()->getLayout() === Navigation::LAYOUT_DROPDOWN) {
$cssClass[] = static::CSS_CLASS_DROPDOWN;
$cssClasses[] = static::CSS_CLASS_DROPDOWN;
$item
->setAttribute('class', static::CSS_CLASS_DROPDOWN_TOGGLE)
->setIcon(static::DROPDOWN_TOGGLE_ICON)
@ -315,12 +315,16 @@ class NavigationRenderer implements RecursiveIterator, NavigationRendererInterfa
}
if ($item->getActive()) {
$cssClass[] = static::CSS_CLASS_ACTIVE;
$cssClasses[] = static::CSS_CLASS_ACTIVE;
}
if ($cssClass = $item->getCssClass()) {
$cssClasses[] = $cssClass;
}
$content = sprintf(
'<li class="%s">',
join(' ', $cssClass)
join(' ', $cssClasses)
);
return $content;
}