2015-09-01 12:48:45 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
namespace Icinga\Web\Navigation;
|
|
|
|
|
|
|
|
use Countable;
|
2015-09-02 15:16:05 +02:00
|
|
|
use Exception;
|
2015-09-01 12:48:45 +02:00
|
|
|
use InvalidArgumentException;
|
|
|
|
use IteratorAggregate;
|
|
|
|
use Icinga\Application\Icinga;
|
2015-09-02 15:16:05 +02:00
|
|
|
use Icinga\Exception\IcingaException;
|
2015-09-01 12:48:45 +02:00
|
|
|
use Icinga\Web\View;
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A navigation item
|
|
|
|
*/
|
|
|
|
class NavigationItem implements Countable, IteratorAggregate
|
|
|
|
{
|
|
|
|
/**
|
2015-09-02 15:42:54 +02:00
|
|
|
* Alternative markup element for items without a url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const LINK_ALTERNATIVE = 'span';
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:32:37 +02:00
|
|
|
* Whether this item is active
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
2015-09-02 15:32:37 +02:00
|
|
|
protected $active;
|
2015-09-01 12:48:45 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-02 15:25:10 +02:00
|
|
|
* The attributes of this item's element
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-09-02 15:25:10 +02:00
|
|
|
protected $attributes;
|
2015-09-01 12:48:45 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-02 15:20:26 +02:00
|
|
|
* This item's children
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @var Navigation
|
|
|
|
*/
|
|
|
|
protected $children;
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:42:54 +02:00
|
|
|
* This item's icon
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:42:54 +02:00
|
|
|
* @var string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
protected $icon;
|
|
|
|
|
|
|
|
/**
|
2015-09-02 13:27:12 +02:00
|
|
|
* This item's name
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 13:27:12 +02:00
|
|
|
* @var string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
2015-09-02 13:27:12 +02:00
|
|
|
protected $name;
|
2015-09-01 12:48:45 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-02 15:27:34 +02:00
|
|
|
* This item's label
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:27:34 +02:00
|
|
|
* @var string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
protected $label;
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:30:35 +02:00
|
|
|
* This item's parent
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:30:35 +02:00
|
|
|
* @var NavigationItem
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
2015-09-02 15:30:35 +02:00
|
|
|
protected $parent;
|
2015-09-01 12:48:45 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-02 15:35:08 +02:00
|
|
|
* This item's url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:35:08 +02:00
|
|
|
* @var Url
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:35:08 +02:00
|
|
|
* Additional parameters for this item's url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-09-02 15:35:08 +02:00
|
|
|
protected $urlParameters;
|
2015-09-01 12:48:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View
|
|
|
|
*
|
2015-09-02 15:33:45 +02:00
|
|
|
* @var View
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
protected $view;
|
|
|
|
|
|
|
|
/**
|
2015-09-02 13:27:12 +02:00
|
|
|
* Create a new NavigationItem
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 13:27:12 +02:00
|
|
|
* @param string $name
|
|
|
|
* @param array $properties
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
2015-09-02 13:27:12 +02:00
|
|
|
public function __construct($name, array $properties = null)
|
2015-09-01 12:48:45 +02:00
|
|
|
{
|
2015-09-02 13:27:12 +02:00
|
|
|
$this->setName($name);
|
2015-09-02 15:20:26 +02:00
|
|
|
$this->children = new Navigation();
|
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
if (! empty($properties)) {
|
|
|
|
$this->setProperties($properties);
|
|
|
|
}
|
2015-09-02 13:27:12 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
$this->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:20:26 +02:00
|
|
|
* Initialize this NavigationItem
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function count()
|
|
|
|
{
|
2015-09-02 15:20:26 +02:00
|
|
|
return $this->getChildren()->count();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getIterator()
|
|
|
|
{
|
2015-09-02 15:20:26 +02:00
|
|
|
return $this->getChildren();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:32:37 +02:00
|
|
|
* Return whether this item is active
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:32:37 +02:00
|
|
|
* @return bool
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getActive()
|
|
|
|
{
|
2015-09-02 15:32:37 +02:00
|
|
|
return $this->active ?: false;
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:32:37 +02:00
|
|
|
* Set whether this item is active
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:32:37 +02:00
|
|
|
* If it's active and has a parent, the parent gets activated as well.
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @param bool $active
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setActive($active = true)
|
|
|
|
{
|
|
|
|
$this->active = (bool) $active;
|
2015-09-02 15:32:37 +02:00
|
|
|
if ($this->active && $this->getParent() !== null) {
|
|
|
|
$this->getParent()->setActive();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
2015-09-02 15:32:37 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:25:10 +02:00
|
|
|
* Return the value of the given element attribute
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:25:10 +02:00
|
|
|
* @param string $name
|
|
|
|
* @param mixed $default
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getAttribute($name, $default = null)
|
|
|
|
{
|
2015-09-02 15:25:10 +02:00
|
|
|
$attributes = $this->getAttributes();
|
|
|
|
return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:25:10 +02:00
|
|
|
* Set the value of the given element attribute
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:25:10 +02:00
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setAttribute($name, $value)
|
|
|
|
{
|
|
|
|
$this->attributes[$name] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:25:10 +02:00
|
|
|
* Return the attributes of this item's element
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:25:10 +02:00
|
|
|
* @return array
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getAttributes()
|
|
|
|
{
|
2015-09-02 15:25:10 +02:00
|
|
|
return $this->attributes ?: array();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:25:10 +02:00
|
|
|
* Set the attributes of this item's element
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @param array $attributes
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setAttributes(array $attributes)
|
|
|
|
{
|
2015-09-02 15:25:10 +02:00
|
|
|
$this->attributes = $attributes;
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:17:26 +02:00
|
|
|
* Add a child to this item
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:17:26 +02:00
|
|
|
* If the child is active this item gets activated as well.
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:17:26 +02:00
|
|
|
* @param NavigationItem $child
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2015-09-02 15:17:26 +02:00
|
|
|
public function addChild(NavigationItem $child)
|
2015-09-01 12:48:45 +02:00
|
|
|
{
|
2015-09-02 15:17:26 +02:00
|
|
|
$this->getChildren()->addItem($child->setParent($this));
|
2015-09-01 12:48:45 +02:00
|
|
|
if ($child->getActive()) {
|
|
|
|
$this->setActive();
|
|
|
|
}
|
2015-09-02 15:17:26 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:21:40 +02:00
|
|
|
* Return this item's children
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:21:40 +02:00
|
|
|
* @return Navigation
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getChildren()
|
|
|
|
{
|
|
|
|
return $this->children;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:20:26 +02:00
|
|
|
* Return whether this item has any children
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:20:26 +02:00
|
|
|
* @return bool
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function hasChildren()
|
|
|
|
{
|
2015-09-02 15:42:54 +02:00
|
|
|
return !$this->getChildren()->isEmpty();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:21:40 +02:00
|
|
|
* Set this item's children
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 12:59:05 +02:00
|
|
|
* @param array|Navigation $children
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2015-09-02 12:59:05 +02:00
|
|
|
public function setChildren($children)
|
2015-09-01 12:48:45 +02:00
|
|
|
{
|
2015-09-02 12:59:05 +02:00
|
|
|
if (is_array($children)) {
|
|
|
|
$children = Navigation::fromArray($children);
|
|
|
|
} elseif (! $children instanceof Navigation) {
|
|
|
|
throw new InvalidArgumentException('Argument $children must be of type array or Navigation');
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:21:40 +02:00
|
|
|
foreach ($children as $item) {
|
|
|
|
$item->setParent($this);
|
|
|
|
}
|
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
$this->children = $children;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:42:54 +02:00
|
|
|
* Return this item's icon
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:42:54 +02:00
|
|
|
* @return string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return $this->icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:42:54 +02:00
|
|
|
* Set this item's icon
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @param string $icon
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setIcon($icon)
|
|
|
|
{
|
2015-09-02 15:42:54 +02:00
|
|
|
$this->icon = $icon;
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 13:27:12 +02:00
|
|
|
* Return this item's name
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 13:27:12 +02:00
|
|
|
* @return string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
2015-09-02 13:27:12 +02:00
|
|
|
public function getName()
|
2015-09-01 12:48:45 +02:00
|
|
|
{
|
2015-09-02 13:27:12 +02:00
|
|
|
return $this->name;
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 13:27:12 +02:00
|
|
|
* Set this item's name
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 13:27:12 +02:00
|
|
|
* @param string $name
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2015-09-02 13:27:12 +02:00
|
|
|
public function setName($name)
|
2015-09-01 12:48:45 +02:00
|
|
|
{
|
2015-09-02 13:27:12 +02:00
|
|
|
$this->name = $name;
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:30:35 +02:00
|
|
|
/**
|
|
|
|
* Set this item's parent
|
|
|
|
*
|
|
|
|
* @param NavigationItem $parent
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setParent(NavigationItem $parent)
|
|
|
|
{
|
|
|
|
$this->parent = $parent;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return this item's parent
|
|
|
|
*
|
|
|
|
* @return NavigationItem
|
|
|
|
*/
|
|
|
|
public function getParent()
|
|
|
|
{
|
|
|
|
return $this->parent;
|
|
|
|
}
|
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
/**
|
2015-09-02 15:27:34 +02:00
|
|
|
* Return this item's label
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:27:34 +02:00
|
|
|
* @return string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getLabel()
|
|
|
|
{
|
2015-09-02 15:27:34 +02:00
|
|
|
return $this->label ?: $this->getName();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:27:34 +02:00
|
|
|
* Set this item's label
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @param string $label
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setLabel($label)
|
|
|
|
{
|
2015-09-02 15:27:34 +02:00
|
|
|
$this->label = $label;
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:35:08 +02:00
|
|
|
* Return this item's url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:35:08 +02:00
|
|
|
* @return Url
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return $this->url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:35:08 +02:00
|
|
|
* Set this item's url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:35:08 +02:00
|
|
|
* @param Url|string $url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2015-09-02 15:35:08 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException If the given url is neither of type
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function setUrl($url)
|
|
|
|
{
|
2015-09-02 15:35:08 +02:00
|
|
|
if (is_string($url)) {
|
|
|
|
$url = Url::fromPath($url);
|
|
|
|
} elseif (! $url instanceof Url) {
|
|
|
|
throw new InvalidArgumentException('Argument $url must be of type string or Url');
|
|
|
|
}
|
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
$this->url = $url;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:35:08 +02:00
|
|
|
* Return all additional parameters for this item's url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:35:08 +02:00
|
|
|
* @return array
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getUrlParameters()
|
|
|
|
{
|
2015-09-02 15:35:08 +02:00
|
|
|
return $this->urlParameters ?: array();
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:35:08 +02:00
|
|
|
* Set additional parameters for this item's url
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @param array $urlParameters
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setUrlParameters(array $urlParameters)
|
|
|
|
{
|
|
|
|
$this->urlParameters = $urlParameters;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:33:45 +02:00
|
|
|
* Return the view
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:33:45 +02:00
|
|
|
* @return View
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function getView()
|
|
|
|
{
|
|
|
|
if ($this->view === null) {
|
2015-09-02 15:33:45 +02:00
|
|
|
$this->setView(Icinga::app()->getViewRenderer()->view);
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
2015-09-02 15:33:45 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this->view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the view
|
|
|
|
*
|
|
|
|
* @param View $view
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setView(View $view)
|
|
|
|
{
|
|
|
|
$this->view = $view;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:26:07 +02:00
|
|
|
* Set this item's properties
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
|
|
|
* @param array $properties
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2015-09-02 15:26:07 +02:00
|
|
|
public function setProperties(array $properties)
|
2015-09-01 12:48:45 +02:00
|
|
|
{
|
|
|
|
foreach ($properties as $name => $value) {
|
|
|
|
$setter = 'set' . ucfirst($name);
|
|
|
|
if (method_exists($this, $setter)) {
|
|
|
|
$this->$setter($value);
|
|
|
|
}
|
|
|
|
}
|
2015-09-02 15:26:07 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:16:05 +02:00
|
|
|
* Return this item rendered to HTML
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:16:05 +02:00
|
|
|
* @return string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$view = $this->getView();
|
2015-09-02 15:16:05 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
$label = $view->escape($this->getLabel());
|
2015-09-02 15:16:05 +02:00
|
|
|
if (($icon = $this->getIcon()) !== null) {
|
2015-09-01 12:48:45 +02:00
|
|
|
$label = $view->icon($icon) . $label;
|
|
|
|
}
|
2015-09-02 15:16:05 +02:00
|
|
|
|
|
|
|
if (($url = $this->getUrl()) !== null) {
|
2015-09-01 12:48:45 +02:00
|
|
|
$content = sprintf(
|
|
|
|
'<a%s href="%s">%s</a>',
|
|
|
|
$view->propertiesToString($this->getAttributes()),
|
|
|
|
$view->url($url, $this->getUrlParameters()),
|
|
|
|
$label
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$content = sprintf(
|
|
|
|
'<%1$s%2$s>%3$s</%1$s>',
|
|
|
|
static::LINK_ALTERNATIVE,
|
|
|
|
$view->propertiesToString($this->getAttributes()),
|
|
|
|
$label
|
|
|
|
);
|
|
|
|
}
|
2015-09-02 15:16:05 +02:00
|
|
|
|
2015-09-01 12:48:45 +02:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-02 15:16:05 +02:00
|
|
|
* Return this item rendered to HTML
|
2015-09-01 12:48:45 +02:00
|
|
|
*
|
2015-09-02 15:16:05 +02:00
|
|
|
* @return string
|
2015-09-01 12:48:45 +02:00
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
2015-09-02 15:16:05 +02:00
|
|
|
try {
|
|
|
|
return $this->render();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return IcingaException::describe($e);
|
|
|
|
}
|
2015-09-01 12:48:45 +02:00
|
|
|
}
|
|
|
|
}
|