/** * Create a MenuItem from a NodeInterface instance. * * @param NodeInterface $node * * @return MenuItem|null If allowEmptyItems is false and this node has * neither URL nor route nor a content that has a * route, returns null. */ public function createFromNode(NodeInterface $node) { $event = new CreateMenuItemFromNodeEvent($node, $this); $this->dispatcher->dispatch(Events::CREATE_ITEM_FROM_NODE, $event); if ($event->isSkipNode()) { if ($node instanceof Menu) { // create an empty menu root to avoid the knp menu from failing. return $this->createItem(''); } return; } $item = $event->getItem() ?: $this->createItem($node->getName(), $node->getOptions()); if (empty($item)) { return; } if ($event->isSkipChildren()) { return $item; } return $this->addChildrenFromNode($node->getChildren(), $item); }
/** * Get children * * @return ArrayCollection|ChildrenCollection */ public function getChildren() { return $this->connectedNode->getChildren(); }
/** * {@inheritdoc} * * @see Knp\Menu.FactoryInterface::createFromNode() */ public function createFromNode(NodeInterface $node) { $item = $this->createItem($node->getName(), $node->getOptions()); /* @var $childNode NodeInterface */ foreach ($node->getChildren() as $childNode) { $item->addChild($this->createFromNode($childNode)); } return $item; }