/**
  * recurse method
  *
  * @param array  $items
  * @param string $parentId
  */
 protected function recurse($items = [], $parentId = 'root')
 {
     foreach ($items as $item) {
         $link = '#';
         $type = null;
         if (array_key_exists('document', $item)) {
             $type = 'document';
             // remove .md extension if present
             $path = ends_with($item['document'], ['.md']) ? Str::remove($item['document'], '.md') : $item['document'];
             $link = $this->codex->url($this->ref->getProject(), $this->ref->getName(), $path);
         } elseif (array_key_exists('href', $item)) {
             $type = 'href';
             $link = $item['href'];
         }
         $id = md5($item['name'] . $link);
         $node = $this->menu->add($id, $item['name'], $parentId);
         $node->setAttribute('href', $link);
         $node->setAttribute('id', $id);
         if (isset($path)) {
             $node->setMeta('path', $path);
         }
         if (isset($item['icon'])) {
             $node->setMeta('icon', $item['icon']);
         }
         if (isset($item['children'])) {
             $type = 'parent';
         }
         $node->setMeta('type', $type);
         if (isset($item['children'])) {
             $this->recurse($item['children'], $id);
         }
     }
 }
Beispiel #2
0
 /**
  * handle method
  *
  * @param \Codex\Contracts\Menus\Menu|\Codex\Menus\Menu $menu
  */
 public function handle(MenuContract $menu, Ref $currentRef)
 {
     $refs = $currentRef->getRefs();
     $project = $currentRef->getProject();
     $menu->setAttribute('title', $currentRef->getName());
     $menu->setAttribute('subtitle', 'version');
     foreach ($refs->all() as $ref) {
         $menu->add($ref->getName(), $ref->getName())->setAttribute(['href' => $project->url('index', $ref->getName())]);
     }
 }