public function transformContent() { /** @var $SMSM SMSManager */ $SMSM = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Manager'); $this->SMSM = $SMSM; $doc = $this->getDocument(); $level = $doc->getAttribute('SMSNavLevel'); $rellevel = $doc->getAttribute('SMSNavRelLevel'); $depth = $doc->getAttribute('SMSNavDepth'); $basePageId = $doc->getAttribute('SMSNavBasePageId'); //// // fetch base page if (!empty($basePageId)) { $basePage = $this->SMSM->getPage($basePageId); } else { /** @var $SMSS SMSSite */ $SMSS = $this->SMSM->getSite(); $basePage = $SMSS->getCurrentPage(); } $basePageLevel = $basePage->getLevel(); //// // evaluate input attributes // level if (strtolower($rellevel) == 'true') { $levelSummand = intval($level); $targetLevel = $basePageLevel + $levelSummand; } else { $targetLevel = intval($level); } if ($targetLevel < 0) { $targetLevel = 0; } // depth if ($depth == 'auto') { $depth = 1; $this->autoDepth = true; } else { $depth = intval($depth); } if ($depth < 1) { $depth = 1; } //// // collect pages to display in first menu level (no subpages, even in case of depth > 1) if ($targetLevel <= $basePageLevel) { // go to target level page in current branch $targetLevelPage = $basePage; while ($targetLevelPage->getLevel() > $targetLevel) { $targetLevelPage = $targetLevelPage->getParent(); } $navPages = $targetLevelPage->getSiblings(true); // include target level page } else { $currentCollectingLevel = $basePageLevel + 1; // because we collect children, not siblings $collectedPages = $basePage->getChildren(); while ($currentCollectingLevel < $targetLevel) { $tmp = []; foreach ($collectedPages as $page) { /** @var $page SMSPage */ $tmp = array_merge($tmp, $page->getChildren()); } $collectedPages = $tmp; $currentCollectingLevel++; } $navPages = $collectedPages; } if (count($navPages) > 0) { $this->buildMenu($navPages, $depth); } }
public function transformContent() { /** @var $SMSM SMSManager */ $SMSM = $this->getDIServiceObject('APF\\extensions\\apfelsms', 'Manager'); $this->SMSM = $SMSM; $doc = $this->getDocument(); $basePageId = $doc->getAttribute('SMSBreadcrumbNavBasePageId'); //// // fetch base page if (!empty($basePageId)) { $basePage = $this->SMSM->getPage($basePageId); } else { $basePage = $this->SMSM->getSite()->getStartPage(); } $currentPage = $this->SMSM->getSite()->getCurrentPage(); $basePageLevel = $basePage->getLevel(); $basePageId = $basePage->getId(); //// // collect all breadcrumbs /** @var $reverseCrumbArray \APF\extensions\apfelsms\biz\pages\SMSPage[] */ $reverseCrumbArray = []; $crumb = $currentPage; do { // Ignore origanisation-/system-nodes (hidden nodes without title) $crumbNavTitle = $crumb->getNavTitle(); if (!($crumb->isHidden() && empty($crumbNavTitle))) { $reverseCrumbArray[] = $crumb; } $oldCrumb = $crumb; $crumb = $oldCrumb->getParent(); } while ($crumb !== null && $basePageLevel <= $oldCrumb->getLevel() && $crumb->getId() != $basePageId); // add the base page, if not same as current page if ($currentPage->getId() != $basePageId) { $reverseCrumbArray[] = $basePage; } /** @var $crumbArray \APF\extensions\apfelsms\biz\pages\SMSPage[] */ $crumbArray = array_reverse($reverseCrumbArray); //// // build breadcrumbs $buffer = ''; $lastKey = count($crumbArray) - 1; $url = $this->getUrlPrototype(); foreach ($crumbArray as $key => $crumb) { $template = $this->getTemplate('breadcrumb'); $linkURL = $crumb->getLink(clone $url); $linkText = $crumb->getNavTitle(); if ($crumb->getId() == $basePageId) { // allow custom title for basePage $linkText = $doc->getAttribute('SMSBreadcrumbNavBasePageIdTitle', $crumb->getNavTitle()); } if (empty($linkText)) { $linkText = $crumb->getId(); } $linkTitle = $linkText; $linkClasses = ' level_' . $crumb->getLevel(); if ($key == $lastKey) { $linkClasses .= ' last active current'; } if ($key == 0) { $linkClasses .= ' first'; } $template->setPlaceHolder('URL', StringAssistant::escapeSpecialCharacters($linkURL)); $template->setPlaceHolder('TITLE', StringAssistant::escapeSpecialCharacters($linkTitle)); $template->setPlaceHolder('TEXT', StringAssistant::escapeSpecialCharacters($linkText)); $template->setPlaceHolder('CLASSES', $linkClasses); $buffer .= $template->transformTemplate(); } $containerTemplate = $this->getTemplate('breadcrumbNavigationContainer'); $containerTemplate->setPlaceHolder('breadcrumbs', $buffer); $containerTemplate->transformOnPlace(); }