/** * This method should be used to establish the requisite * structure needed by the application or bundle of the * content repository. * * @param ManagerRegistry $registry */ public function init(ManagerRegistry $registry) { $className = self::MENU_DOCUMENT_CLASS_NAME; /** @var DocumentManager $dm */ $dm = $registry->getManagerForClass($className); /** @var Generic $parent */ $menuRoot = $this->menuProvider->getMenuRoot(); $parent = $dm->find(null, $menuRoot); if (!$parent) { throw new \InvalidArgumentException("Cannot find menu base path '{$this->menuProvider}'."); } foreach ($this->menus as $menuName => $menuLabel) { /** @var Menu $menu */ $menu = $dm->find($className, $menuRoot . '/' . $menuName); if (!$menu) { $menu = new $className(); } $menu->setName($menuName); $menu->setLabel($menuLabel); $menu->setParentDocument($parent); $dm->persist($menu); } $dm->flush(); }
/** * {@inheritdoc} */ public function execute(BlockContextInterface $blockContext, Response $response = null) { $settings = array('id' => $this->menuProvider->getMenuRoot(), 'selected' => ''); $settings = array_merge($blockContext->getSettings(), $settings); return $this->renderResponse($blockContext->getTemplate(), array('block_context' => $blockContext, 'block' => $blockContext->getBlock(), 'settings' => $settings, 'menu_node_admin' => $this->menuNodeAdmin), $response); }