/** * Add a child menu node, automatically setting the parent node. * * @param NodeInterface $child * * @return NodeInterface - The newly added child node. */ public function addChild(NodeInterface $child) { if ($child instanceof MenuNode) { $child->setParentObject($this); } return parent::addChild($child); }
/** * Get children * * @return ArrayCollection|ChildrenCollection */ public function getChildren() { return $this->connectedNode->getChildren(); }
/** * 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); }
/** * {@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; }