/** * @return a Navigation instance with the specified information */ protected function createMenuNode(DocumentManager $dm, $parent, $name, $label, $content, $uri = null, $route = null) { if (!$parent instanceof MenuNode && !$parent instanceof Menu) { $menuNode = new Menu(); } else { $menuNode = new MenuNode(); } $menuNode->setParent($parent); $menuNode->setName($name); $dm->persist($menuNode); // do persist before binding translation if (null !== $content) { $menuNode->setContent($content); } else { if (null !== $uri) { $menuNode->setUri($uri); } else { if (null !== $route) { $menuNode->setRoute($route); } } } if (is_array($label)) { foreach ($label as $locale => $l) { $menuNode->setLabel($l); $dm->bindTranslation($menuNode, $locale); } } else { $menuNode->setLabel($label); } return $menuNode; }
public function load(ObjectManager $dm) { $this->yaml = new Parser(); parent::load($dm); $data = $this->yaml->parse(file_get_contents(__DIR__ . '/../../Resources/data/external.yml')); $basepath = $this->getBasePath(); $home = $dm->find(null, $basepath); $route = new MultilangRoute(); $route->setPosition($home, 'dynamic'); $route->setDefault('_controller', 'AcmeMainBundle:Demo:dynamic'); $dm->persist($route); foreach ($data['static'] as $name => $overview) { $menuItem = new MenuNode(); $menuItem->setName($name); $menuItem->setParent($home); if (!empty($overview['route'])) { if (!empty($overview['uri'])) { $route = new MultilangRedirectRoute(); $route->setPosition($home, $overview['route']); $route->setUri($overview['uri']); $dm->persist($route); } else { $route = $dm->find(null, $basepath . '/' . $overview['route']); } $menuItem->setRoute($route->getId()); } else { $menuItem->setUri($overview['uri']); } $dm->persist($menuItem); foreach ($overview['label'] as $locale => $label) { $menuItem->setLabel($label); if ($locale) { $dm->bindTranslation($menuItem, $locale); } } } $dm->flush(); }