/** * Render a navigation displaying children starting from a section * * @param Request $request The Request * @param mixed $section The section entity or section id to start from * @param int $maxLevel The level maximum limit, this is the rendering loop level limit, not the section entity level * @param bool $exploded When false only the currently selected tree path is displayed * @param string $template Force the template code to use * @param array $attr Array of attribure to add to the element (Ex. id="aaa" class="bbb") * * @return Response * * @throws \Exception */ public function fromSectionAction(Request $request, $section, $maxLevel = 10, $exploded = false, $template = '', $attr = []) { // Cache $response = new Response(); $response->setPublic(); $response->setEtag($this->sectionRepository->findLastUpdate()); if ($response->isNotModified($request)) { return $response; } // Rebuild the cache if (is_numeric($section)) { $section = $this->sectionRepository->findOneWithChildren($section); } $elements = []; if ($parents = $section->getParents()) { $elements = $parents[1]->getChildren(); } elseif (count($section->getChildren())) { $elements = $section->getChildren(); } $template = $template ? '_' . $template : ''; $navigationBuilder = $this->get('unifik_system.navigation_builder'); $navigationBuilder->setElements($elements, true, $maxLevel); $navigationBuilder->setSelectedElement($this->getCore()->getSection()); $navigationBuilder->build(); $elements = $navigationBuilder->getElements(); return $this->render('UnifikSystemBundle:Frontend/Navigation:from_section' . $template . '.html.twig', array('sections' => $elements, 'maxLevel' => $maxLevel, 'currentSection' => $this->getSection(), 'attr' => $attr, 'exploded' => $exploded), $response); }