mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
NavigationItem: Overwrite the property in method setAttributes()
A setter sets something instead of patching it. refs #5600
This commit is contained in:
parent
5efcb18fa0
commit
8a29660226
@ -34,11 +34,11 @@ class NavigationItem implements Countable, IteratorAggregate
|
|||||||
protected $active = false;
|
protected $active = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attributes of the item's element
|
* The attributes of this item's element
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $attributes = array();
|
protected $attributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This item's children
|
* This item's children
|
||||||
@ -168,49 +168,45 @@ class NavigationItem implements Countable, IteratorAggregate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an attribute's value of the item's element
|
* Return the value of the given element attribute
|
||||||
*
|
*
|
||||||
* @param string $name Name of the attribute
|
* @param string $name
|
||||||
* @param mixed $default Default value
|
* @param mixed $default
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getAttribute($name, $default = null)
|
public function getAttribute($name, $default = null)
|
||||||
{
|
{
|
||||||
$name = (string) $name;
|
$attributes = $this->getAttributes();
|
||||||
if (array_key_exists($name, $this->attributes)) {
|
return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
|
||||||
return $this->attributes[$name];
|
|
||||||
}
|
|
||||||
return $default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an attribute of the item's element
|
* Set the value of the given element attribute
|
||||||
*
|
*
|
||||||
* @param string $name Name of the attribute
|
* @param string $name
|
||||||
* @param mixed $value Value of the attribute
|
* @param mixed $value
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setAttribute($name, $value)
|
public function setAttribute($name, $value)
|
||||||
{
|
{
|
||||||
$name = (string) $name;
|
|
||||||
$this->attributes[$name] = $value;
|
$this->attributes[$name] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the item's attributes
|
* Return the attributes of this item's element
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getAttributes()
|
public function getAttributes()
|
||||||
{
|
{
|
||||||
return $this->attributes;
|
return $this->attributes ?: array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the item's attributes
|
* Set the attributes of this item's element
|
||||||
*
|
*
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
*
|
*
|
||||||
@ -218,9 +214,7 @@ class NavigationItem implements Countable, IteratorAggregate
|
|||||||
*/
|
*/
|
||||||
public function setAttributes(array $attributes)
|
public function setAttributes(array $attributes)
|
||||||
{
|
{
|
||||||
foreach ($attributes as $name => $value) {
|
$this->attributes = $attributes;
|
||||||
$this->setAttribute($name, $value);
|
|
||||||
}
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user