Skip to content

Commit

Permalink
lib: Support setting CSS class for li on navigation items
Browse files Browse the repository at this point in the history
refs #5543
  • Loading branch information
lippserd committed Sep 28, 2015
1 parent a408636 commit ed6da19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
30 changes: 30 additions & 0 deletions library/Icinga/Web/Navigation/NavigationItem.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -200,6 +207,29 @@ public function setActive($active = true)
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
*
Expand Down
12 changes: 8 additions & 4 deletions library/Icinga/Web/Navigation/Renderer/NavigationRenderer.php
Expand Up @@ -304,23 +304,27 @@ public function endChildrenMarkup()
*/
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)
->setUrl('#');
}

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;
}
Expand Down

0 comments on commit ed6da19

Please sign in to comment.