/**
  * Visit the menu tree leading to this path with a specified visitor.
  *
  * Implementation: the visitor is reset after each child list
  *
  * @see getMenu()
  * @param string $path the url (without eventual prefix from routing config)
  * @param ItemVisitorInterface $visitor to gather information from a node, with the same behaviour and additional methods as explained in createMenuVisitor()
  * @param bool $skiproot whether to not include the root node in the collection, defaults to skipping it
  * @param int $depth depth to follow unselected node children. defaults to 0 (do not follow). -1 means unlimited
  *
  * @return array structure with entries for each node: title, url, selected (parent of $url or $url itselves), node (the phpcr node), children (array, empty array on no children. false if not selected node and deeper away from selected node than depth.). if you skip the root, the uppermost thing is directly an array of children
  */
 public function visitMenu($path, $visitor, $skiproot = true, $depth = 0)
 {
     if ($skiproot) {
         //have a fake parentrecord
         $tree = array('selected' => true, 'node' => $this->rootnode);
     } else {
         $this->rootnode->accept($visitor);
         $tree = $visitor->getArray();
         $tree = reset($tree);
         //visitor just was at the root node, there is exactly one
     }
     $children = $this->visitMenuRecursive($tree, $path, $visitor, $depth, 0);
     if ($skiproot) {
         $tree = $children;
     } else {
         $tree['children'] = $children;
     }
     return $tree;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function accept(ItemVisitorInterface $visitor)
 {
     return $this->node->accept($visitor);
 }
 public function testAccept()
 {
     $mock = $this->getMock('PHPCR\\ItemVisitorInterface', array('visit'));
     $mock->expects($this->once())->method('visit')->with($this->equalTo($this->node));
     $this->node->accept($mock);
 }