From a6b2c23684b39b97693403e1b5fe2fd470db4c6a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 4 Sep 2015 09:08:20 +0200 Subject: [PATCH] Update navigation rendering code to fit the previous adjustments refs #5600 --- library/Icinga/Web/Navigation/Navigation.php | 1 + .../Renderer/NavigationRenderer.php | 305 ++++++++++-------- .../Renderer/NavigationRendererInterface.php | 68 ++-- .../Renderer/RecursiveNavigationRenderer.php | 133 +++++--- 4 files changed, 285 insertions(+), 222 deletions(-) diff --git a/library/Icinga/Web/Navigation/Navigation.php b/library/Icinga/Web/Navigation/Navigation.php index bcd528b76..781eb4e8d 100644 --- a/library/Icinga/Web/Navigation/Navigation.php +++ b/library/Icinga/Web/Navigation/Navigation.php @@ -18,6 +18,7 @@ use Icinga\Exception\ConfigurationError; use Icinga\Exception\IcingaException; use Icinga\Exception\ProgrammingError; use Icinga\Util\String; +use Icinga\Web\Navigation\Renderer\RecursiveNavigationRenderer; /** * Container for navigation items diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationRenderer.php index 60cfcf900..0c47fc0d4 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationRenderer.php @@ -1,11 +1,15 @@ skipOuterElement = $skipOuterElement; $this->iterator = $navigation->getIterator(); $this->navigation = $navigation; - $this->flags = $flags; + $this->content = array(); + } + + /** + * {@inheritdoc} + */ + public function setElementTag($tag) + { + $this->elementTag = $tag; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getElementTag() + { + return $this->elementTag ?: static::OUTER_ELEMENT_TAG; + } + + /** + * {@inheritdoc} + */ + public function setCssClass($class) + { + $this->cssClass = $class; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getCssClass() + { + return $this->cssClass; + } + + /** + * {@inheritdoc} + */ + public function setHeading($heading) + { + $this->heading = $heading; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getHeading() + { + return $this->heading; + } + + /** + * Return the view + * + * @return View + */ + public function view() + { + if ($this->view === null) { + $this->setView(Icinga::app()->getViewRenderer()->view); + } + + return $this->view; + } + + /** + * Set the view + * + * @param View $view + * + * @return $this + */ + public function setView(View $view) + { + $this->view = $view; + return $this; } /** @@ -87,7 +170,7 @@ class NavigationRenderer implements RecursiveIterator, NavigationRendererInterfa */ public function getChildren() { - return new static($this->current()->getChildren(), $this->flags & static::NAV_DISABLE); + return new static($this->current()->getChildren(), $this->skipOuterElement); } /** @@ -100,7 +183,8 @@ class NavigationRenderer implements RecursiveIterator, NavigationRendererInterfa /** * {@inheritdoc} - * @return \Icinga\Web\Navigation\NavigationItem + * + * @return NavigationItem */ public function current() { @@ -129,9 +213,8 @@ class NavigationRenderer implements RecursiveIterator, NavigationRendererInterfa public function rewind() { $this->iterator->rewind(); - if (! (bool) ($this->flags & static::NAV_DISABLE) && ! $this->inIteration) { + if (! $this->skipOuterElement) { $this->content[] = $this->beginMarkup(); - $this->inIteration = true; } } @@ -141,83 +224,69 @@ class NavigationRenderer implements RecursiveIterator, NavigationRendererInterfa public function valid() { $valid = $this->iterator->valid(); - if (! (bool) ($this->flags & static::NAV_DISABLE) && ! $valid && $this->inIteration) { + if (! $this->skipOuterElement && !$valid) { $this->content[] = $this->endMarkup(); - $this->inIteration = false; } + return $valid; } /** - * Begin navigation markup + * Return the opening markup for the navigation * - * @return string + * @return string */ public function beginMarkup() { $content = array(); - if ($this->flags & static::NAV_MAJOR) { - $el = 'nav'; - } else { - $el = 'div'; - } - if (($elCssClass = $this->getCssClass()) !== null) { - $elCss = ' class="' . $elCssClass . '"'; - } else { - $elCss = ''; - } $content[] = sprintf( '<%s%s role="navigation">', - $el, - $elCss + $this->getElementTag(), + $this->getCssClass() !== null ? ' class="' . $this->getCssClass() . '"' : '' ); $content[] = sprintf( '%2$s', static::HEADING_RANK, - $this->getView()->escape($this->getHeading()) + $this->view()->escape($this->getHeading()) ); $content[] = $this->beginChildrenMarkup(); - return implode("\n", $content); + return join("\n", $content); } /** - * End navigation markup + * Return the closing markup for the navigation * - * @return string + * @return string */ public function endMarkup() { $content = array(); $content[] = $this->endChildrenMarkup(); - if ($this->flags & static::NAV_MAJOR) { - $content[] = ''; - } else { - $content[] = ''; - } - return implode("\n", $content); + $content[] = 'getElementTag() . '>'; + return join("\n", $content); } /** - * Begin children markup + * Return the opening markup for multiple navigation items * - * @return string + * @return string */ public function beginChildrenMarkup() { - $ulCssClass = static::CSS_CLASS_NAV; - if ($this->navigation->getLayout() & Navigation::LAYOUT_TABS) { - $ulCssClass .= ' ' . static::CSS_CLASS_NAV_TABS; + $cssClass = array(static::CSS_CLASS_NAV); + if ($this->navigation->getLayout() === Navigation::LAYOUT_TABS) { + $cssClass[] = static::CSS_CLASS_NAV_TABS; + } elseif ($this->navigation->getLayout() === Navigation::LAYOUT_DROPDOWN) { + $cssClass[] = static::CSS_CLASS_NAV_DROPDOWN; } - if ($this->navigation->getLayout() & Navigation::LAYOUT_DROPDOWN) { - $ulCssClass .= ' ' . static::CSS_CLASS_NAV_DROPDOWN; - } - return '