public function buildForm(FormBuilderInterface $builder, array $options = array()) { $builder->add('name', null, array('label' => 'form.menu_name', 'translation_domain' => 'GloryMenuBundle'))->add('label', null, array('label' => 'form.menu_label', 'translation_domain' => 'GloryMenuBundle')); switch ($options['type']) { case 'root': $builder->add('template', null, array('label' => 'form.menu_template', 'translation_domain' => 'GloryMenuBundle')); break; default: $menuRoot = $options['data']->getRoot(); $choice = $this->generateChildrenChoice($menuRoot); $builder->add('uri', null, array('label' => 'form.menu_uri', 'translation_domain' => 'GloryMenuBundle')); $builder->add('icon', null, array('label' => 'form.menu_icon', 'translation_domain' => 'GloryMenuBundle')); $builder->add('parent', 'entity', array('class' => $this->menuManager->getClass(), 'property' => 'treename', 'choices' => $choice, 'label' => 'form.menu_parent', 'translation_domain' => 'GloryMenuBundle')); break; } }
/** * * @param MenuManager $menuManager */ public function __construct(MenuManager $menuManager, UrlGeneratorInterface $router) { $this->menuManager = $menuManager; $navigation = $this->menuManager->createMenu(); $navigation->setName('admin_navigation'); $navigation->setLabel('Admin Navigation'); $navigation->setTemplate('GloryAdminBundle:Menu:navigation.html.twig'); $sidebar = $this->menuManager->createMenu(); $sidebar->setName('admin_sidebar'); $sidebar->setLabel('Admin Sidebar'); $sidebar->setTemplate('template', 'GloryAdminBundle:Menu:sidebar.html.twig'); $dashboard = $this->menuManager->createMenu(); $dashboard->setName('dashboard'); $dashboard->setLabel('Dashboard'); $dashboard->setRoute('glory_admin_dashboard'); $dashboard->setUri($router->generate('glory_admin_dashboard')); $dashboard->setIcon('fa fa-dashboard'); $sidebar->addChild($dashboard); $this->menus = array('admin_navigation' => $navigation, 'admin_sidebar' => $sidebar); }
/** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('data_class' => $this->menuManager->getClass())); }
/** * Checks whether a menu exists in this provider * * @param string $name * @param array $options * @return bool */ public function has($name, array $options = array()) { return $this->menuManager->findMenuByName($name) ? true : false; }