mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
NavigationItem: Make it having a name instead of a id..
..and require it as first argument on construction time. refs #5600
This commit is contained in:
parent
b3159ee60d
commit
f449c78dbf
@ -8,10 +8,10 @@ use ArrayIterator;
|
|||||||
use Countable;
|
use Countable;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use IteratorAggregate;
|
use IteratorAggregate;
|
||||||
use Icinga\Authentication\Auth;
|
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
|
use Icinga\Authentication\Auth;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
@ -19,47 +19,6 @@ use Icinga\Util\String;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for navigation items
|
* Container for navigation items
|
||||||
*
|
|
||||||
* Usage example:
|
|
||||||
* <code>
|
|
||||||
* <?php
|
|
||||||
*
|
|
||||||
* namespace Icinga\Example;
|
|
||||||
*
|
|
||||||
* use Icinga\Web\Navigation\DropdownItem;
|
|
||||||
* use Icinga\Web\Navigation\Navigation;
|
|
||||||
* use Icinga\Web\Navigation\NavigationItem;
|
|
||||||
*
|
|
||||||
* $navigation = new Navigation();
|
|
||||||
* $navigation->setLayout(Navigation::LAYOUT_TABS);
|
|
||||||
* $home = new NavigationItem();
|
|
||||||
* $home
|
|
||||||
* ->setIcon('home')
|
|
||||||
* ->setLabel('Home');
|
|
||||||
* ->setUrl('/home');
|
|
||||||
* $logout = new NavigationItem();
|
|
||||||
* $logout
|
|
||||||
* ->setIcon('logout')
|
|
||||||
* ->setLabel('Logout')
|
|
||||||
* ->setUrl('/logout');
|
|
||||||
* $dropdown = new DropdownItem();
|
|
||||||
* $dropdown
|
|
||||||
* ->setIcon('user')
|
|
||||||
* ->setLabel('Preferences');
|
|
||||||
* $preferences = new NavigationItem();
|
|
||||||
* $preferences
|
|
||||||
* ->setIcon('preferences');
|
|
||||||
* ->setLabel('preferences')
|
|
||||||
* ->setUrl('/preferences');
|
|
||||||
* $dropdown->addChild($preferences);
|
|
||||||
* $navigation
|
|
||||||
* ->addItem($home)
|
|
||||||
* ->addItem($logout);
|
|
||||||
* ->addItem($dropdown);
|
|
||||||
* echo $navigation
|
|
||||||
* ->getRenderer()
|
|
||||||
* ->setCssClass('example-nav')
|
|
||||||
* ->render();
|
|
||||||
*/
|
*/
|
||||||
class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
||||||
{
|
{
|
||||||
@ -92,14 +51,14 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
protected static $types;
|
protected static $types;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation items
|
* This navigation's items
|
||||||
*
|
*
|
||||||
* @var NavigationItem[]
|
* @var NavigationItem[]
|
||||||
*/
|
*/
|
||||||
protected $items = array();
|
protected $items = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation layout
|
* This navigation's layout
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
@ -240,28 +199,25 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
$item = $name;
|
$item = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[$item->getName()] = $item;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the item with the given ID
|
* Return the item with the given name
|
||||||
*
|
*
|
||||||
* @param mixed $id
|
* @param string $name
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
*
|
*
|
||||||
* @return NavigationItem|mixed
|
* @return NavigationItem|mixed
|
||||||
*/
|
*/
|
||||||
public function getItem($id, $default = null)
|
public function getItem($name, $default = null)
|
||||||
{
|
{
|
||||||
if (isset($this->items[$id])) {
|
return isset($this->items[$name]) ? $this->items[$name] : $default;
|
||||||
return $this->items[$id];
|
|
||||||
}
|
|
||||||
return $default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the items
|
* Return this navigation's items
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -281,7 +237,7 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether the navigation is empty
|
* Return whether this navigation is empty
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -291,7 +247,7 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the layout
|
* Return this navigation's layout
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
@ -301,7 +257,7 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the layout
|
* Set this navigation's layout
|
||||||
*
|
*
|
||||||
* @param int $layout
|
* @param int $layout
|
||||||
*
|
*
|
||||||
@ -314,7 +270,7 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the navigation renderer
|
* Create and return the renderer for this navigation
|
||||||
*
|
*
|
||||||
* @return RecursiveNavigationRenderer
|
* @return RecursiveNavigationRenderer
|
||||||
*/
|
*/
|
||||||
|
@ -53,11 +53,11 @@ class NavigationItem implements Countable, IteratorAggregate
|
|||||||
protected $icon;
|
protected $icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item's ID
|
* This item's name
|
||||||
*
|
*
|
||||||
* @var mixed
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $id;
|
protected $name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Label
|
* Label
|
||||||
@ -95,15 +95,18 @@ class NavigationItem implements Countable, IteratorAggregate
|
|||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new navigation item
|
* Create a new NavigationItem
|
||||||
*
|
*
|
||||||
|
* @param string $name
|
||||||
* @param array $properties
|
* @param array $properties
|
||||||
*/
|
*/
|
||||||
public function __construct(array $properties = array())
|
public function __construct($name, array $properties = null)
|
||||||
{
|
{
|
||||||
|
$this->setName($name);
|
||||||
if (! empty($properties)) {
|
if (! empty($properties)) {
|
||||||
$this->setProperties($properties);
|
$this->setProperties($properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->children = new Navigation();
|
$this->children = new Navigation();
|
||||||
$this->init();
|
$this->init();
|
||||||
}
|
}
|
||||||
@ -309,25 +312,25 @@ class NavigationItem implements Countable, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the item's ID
|
* Return this item's name
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getId()
|
public function getName()
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the item's ID
|
* Set this item's name
|
||||||
*
|
*
|
||||||
* @param mixed $id ID of the item
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setId($id)
|
public function setName($name)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->name = $name;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user