Example #1
0
 /**
  * @Hook("projects:resolved:node")
  * @param \Codex\Contracts\Projects\Projects $projects
  * @param \Codex\Projects\Project            $project
  * @param \Codex\Menus\Node                  $node
  *
  * @throws \Codex\Exception\CodexException
  */
 public function projectsResolvedNode(Projects $projects, Project $project, Node $node)
 {
     if (false === $this->hasEnabledAuth($project)) {
         return;
     }
     if (false === $project->hasAccess()) {
         $node->setMeta('hidden', true);
         // if all neighbors are hidden, hide the parent as well
         if ($node->hasParent() && $node->neighbors()->where('meta.hidden', true)->count() === count($node->getNeighbors())) {
             $node->getParent()->setMeta('hidden', true);
         }
     }
 }
Example #2
0
 /**
  * Add a menu item
  *
  * @param        $id
  * @param        $value
  * @param string $parent
  * @param array  $meta
  * @param array  $attributes
  *
  * @return \Codex\Menus\Node
  */
 public function add($id, $value, $parent = 'root', array $meta = [], array $attributes = [])
 {
     $node = new Node($id, $this, $value);
     $node->setMeta($meta);
     $node->setAttribute($attributes);
     if ($this->items->has($parent)) {
         $parentNode = $this->items->get($parent);
         $parentNode->addChild($node);
         //            $node->setParent($parentNode);
         $node->setMeta('data-parent', $parent);
     }
     $this->items->put($id, $node);
     return $node;
 }