Web\Menu: make use of Web\Url

refs #7083
This commit is contained in:
Thomas Gelf 2014-09-04 19:18:09 +02:00
parent dd943c3aa7
commit 0f8d5bddba
2 changed files with 19 additions and 7 deletions

View File

@ -4,12 +4,13 @@
namespace Icinga\Web;
use Icinga\Exception\ConfigurationError;
use Zend_Config;
use RecursiveIterator;
use Zend_Config;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Url;
class Menu implements RecursiveIterator
{
@ -278,13 +279,17 @@ class Menu implements RecursiveIterator
/**
* Set the url of this menu
*
* @param string $url The url to set for this menu
* @param Url|string $url The url to set for this menu
*
* @return self
*/
public function setUrl($url)
{
$this->url = $url;
if ($url instanceof Url) {
$this->url = $url;
} else {
$this->url = Url::fromPath($url);
}
return $this;
}

View File

@ -33,7 +33,11 @@ class MenuRenderer extends RecursiveIteratorIterator
*/
public function __construct(Menu $menu, $url = null)
{
$this->url = $url;
if ($url instanceof Url) {
$this->url = $url;
} else {
$this->url = Url::fromPath($url);
}
parent::__construct($menu, RecursiveIteratorIterator::CHILD_FIRST);
}
@ -89,7 +93,7 @@ class MenuRenderer extends RecursiveIteratorIterator
{
return sprintf(
'<a href="%s">%s%s</a>',
$child->getUrl() ? Url::fromPath($child->getUrl()) : '#',
$child->getUrl() ?: '#',
$child->getIcon() ? '<img src="' . Url::fromPath($child->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($child->getTitle())
);
@ -146,6 +150,9 @@ class MenuRenderer extends RecursiveIteratorIterator
*/
protected function isActive(Menu $child)
{
return html_entity_decode(rawurldecode($this->url)) === html_entity_decode(rawurldecode($child->getUrl()));
if (! $this->url) return false;
if (! ($childUrl = $child->getUrl())) return false;
return $this->url && $this->url->matches($childUrl);
}
}