/** * @return string html output */ public function render() { $htmlBuilder = new HtmlBuilder(); if ($this->isReverse()) { $breadcrumbIterator = $this->getBreadcrumbs()->getReverseIterator(); } else { $breadcrumbIterator = $this->getBreadcrumbs()->getIterator(); } $breakcrumbsItems = array(); foreach ($breadcrumbIterator as $breadcrumbObject) { if (!$this->hasSkipLinks() && $breadcrumbObject->hasUrl()) { $breakcrumbInner = new HtmlAnchor($breadcrumbObject->getUrl(), $breadcrumbObject->getTitle()); } else { $breakcrumbInner = $breadcrumbObject->getTitle(); } switch ($this->getTag()) { case 'div': $breadcrumbOuter = new HtmlDiv($breakcrumbInner); break; case 'span': $breadcrumbOuter = new HtmlSpan($breakcrumbInner); break; case 'ul': case 'ol': case 'li': $breadcrumbOuter = new HtmlListItem($breakcrumbInner); break; default: $breadcrumbOuter = $breakcrumbInner; break; } $breakcrumbsItems[] = $breadcrumbOuter; } // surround breadcrumb string a container, depending on the tag switch ($this->getTag()) { case 'ol': $breadcrumbContainer = new HtmlListOrdered(); $breadcrumbContainer->setChildElements($breakcrumbsItems); foreach ($this->getOptionsPathObject()->get() as $key => $value) { // prevent, that already set attributes are overwritten by options if (!$breadcrumbContainer->hasAttribute($key)) { $breadcrumbContainer->setAttribute($key, $value); } } return $htmlBuilder->render($breadcrumbContainer); case 'ul': $breadcrumbContainer = new HtmlListUnordered(); $breadcrumbContainer->setChildElements($breakcrumbsItems); foreach ($this->getOptionsPathObject()->get() as $key => $value) { // prevent, that already set attributes are overwritten by options if (!$breadcrumbContainer->hasAttribute($key)) { $breadcrumbContainer->setAttribute($key, $value); } } return $htmlBuilder->render($breadcrumbContainer); default: // concat breadcrumb to one string return $breadcrumbContainerContent = implode($this->getSeparator(), $breakcrumbsItems); } return null; }
/** * @return void */ public function testSetClass() { $htmlBuilder = new HtmlBuilder(); $htmlElementObject = new HtmlListOrdered(); $htmlElementObject->setClass('testClass'); $this->assertEquals('<ol class="testClass" />', $htmlBuilder->render($htmlElementObject)); }