Beispiel #1
0
 /**
  * Render page
  *
  * @param \SpotOnLive\Navigation\Navigation\Page $page
  * @param null $maxDepth
  * @param int $depth
  * @return null|string
  * @throws \SpotOnLive\Navigation\Exceptions\NoRouteException
  */
 public function renderPage(Page $page, $maxDepth = null, $depth = 0)
 {
     // Check for depth
     if (!is_null($maxDepth) && $depth > $maxDepth) {
         return null;
     }
     $options = $page->getOptions()->get('options');
     $classes = [];
     // Check if the page should be rendered
     if (!$options['render']) {
         return null;
     }
     // Check for assertions
     if (isset($options['assertion'])) {
         $this->validateAssertionService();
         if (!$this->assertionService->isGranted($options['assertion'], $this->getUser())) {
             return null;
         }
     }
     // CSS class for li
     if ($options['li_class']) {
         $classes[] = $options['li_class'];
     }
     // Active page
     if ($page->isActive()) {
         $classes[] = 'active';
     }
     $html = sprintf("      <a href=\"%s\"%s>%s</a>\n", $page->getUrl(), $page->getAttributes('a'), $page->getLabel());
     $pages = $page->getPages();
     if (count($pages) && (is_null($maxDepth) || $maxDepth != $depth)) {
         $ul_class = $options['ul_class'];
         $html .= sprintf("      <ul class=\"%s\"%s>\n", $ul_class, $page->getAttributes('ul'));
         foreach ($pages as $subPage) {
             $html .= $this->renderPage($subPage, $maxDepth, $depth + 1);
         }
         $html .= "      </ul>\n";
     }
     // Use wrapper from config
     $wrappedHtml = sprintf($options['wrapper'], $html);
     // Wrap in <li> tag
     $li = sprintf("   <li class=\"%s\"%s>\n%s    </li>\n", implode(" ", $classes), $page->getAttributes('li'), $wrappedHtml);
     return $li;
 }
Beispiel #2
0
 /**
  * Render page
  *
  * @param \SpotOnLive\Navigation\Navigation\Page $page
  * @param null $maxDepth
  * @param int $depth
  * @return null|string
  * @throws \SpotOnLive\Navigation\Exceptions\NoRouteException
  */
 public function renderPage(Page $page, $maxDepth = null, $depth = 0)
 {
     // Check for depth
     if (!is_null($maxDepth) && $depth > $maxDepth) {
         return null;
     }
     $options = $page->getOptions()->get('options');
     $classes = [];
     // Check if the page should be rendered
     if (!$options['render']) {
         return null;
     }
     // Check for assertions
     if (isset($options['assertion'])) {
         $this->validateAssertionService();
         if (!$this->assertionService->isGranted($options['assertion'], $this->getUser())) {
             return null;
         }
     }
     // CSS class for li
     if ($options['li_class']) {
         $classes[] = $options['li_class'];
     }
     // Active page
     if ($page->isActive()) {
         $classes[] = 'active';
     }
     $html = "   <li class=\"" . implode(" ", $classes) . "\"" . $page->getAttributes('li') . ">\n";
     $html .= '      <a href="' . $page->getUrl() . '"' . $page->getAttributes('a') . '>' . $page->getLabel() . "</a>\n";
     $pages = $page->getPages();
     if (count($pages) && (is_null($maxDepth) || $maxDepth != $depth)) {
         $ul_class = $options['ul_class'];
         $html .= "      <ul class=\"" . $ul_class . "\"" . $page->getAttributes('ul') . ">\n";
         foreach ($pages as $subPage) {
             $html .= $this->renderPage($subPage, $maxDepth, $depth + 1);
         }
         $html .= "      </ul>\n";
     }
     $html .= "    </li>\n";
     return $html;
 }