Gc\Component\Navigation::render PHP Method

render() public method

Render navigation
public render ( array $documents = null, string $parentUrl = null ) : array
$documents array Let of \Gc\Document\Model
$parentUrl string Parent url
return array
    public function render(array $documents = null, $parentUrl = null)
    {
        $navigation = array();
        $documents = $this->checkDocuments($documents);
        foreach ($documents as $document) {
            if ($document->isPublished()) {
                $data = array();
                $data['label'] = $document->getName();
                $data['uri'] = $this->getBasePath() . ltrim(($parentUrl !== null ? trim($parentUrl, '/') . '/' : '') . $document->getUrlKey(), '/');
                $data['visible'] = $document->showInNav();
                $data['active'] = $data['uri'] == $this->requestUri;
                $this->renderChildren($document, $parentUrl, $data);
                $navigation['document-' . $document->getId()] = $data;
            }
        }
        return $navigation;
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testRenderWithChildrenActivePageOnTheForthDocument()
 {
     Registry::get('Application')->getRequest()->getUri()->setPath('/url-key/children-key/second-child-key');
     $this->object = new Navigation();
     $this->object->useActiveBranch(true);
     $array = $this->object->render();
     $this->assertTrue(count($array) > 0);
 }