public function testParameters() { $menuItem = new MenuItem(); $parameters = array(); $expected = $parameters; $menuItem->setParameters($parameters); $actual = $menuItem->getParameters(); $this->assertSame($expected, $actual); }
/** * Create a new menu or menuitem. * * @Route( * "/menu/create/{type}/{locale}", * name="opifer_cms_menu_create" * ) * * @param Request $request * @param integer $id * @param string $type * @param string $locale * * @return Response */ public function createAction(Request $request, $type = 'item', $locale = null) { $em = $this->getDoctrine()->getManager(); $locales = $this->container->getParameter('opifer_cms.allowed_locales'); $defaultLocale = $this->container->getParameter('locale'); $tr = $this->get('translator'); if ($type == 'group') { $menu = new MenuGroup(); } else { $menu = new MenuItem(); } if (count($locales) > 1) { $factory = new MenuFactory(); $localeMenu = $factory->createItem('localeMenu'); $localeMenu->addChild('default', array('uri' => $this->generateUrl('opifer_cms_menu_edit', ['id' => $menu->getId() ? $menu->getId() : 0]), 'label' => $tr->trans('Default'))); foreach ($locales as $plocale) { if ($plocale === $defaultLocale) { continue; } $localeMenu->addChild($plocale, ['uri' => $this->generateUrl('opifer_cms_menu_edit', ['id' => $menu->getId() ? $menu->getId() : 0, 'locale' => $plocale]), 'label' => $tr->trans($plocale)]); } foreach ($localeMenu->getChildren() as $localeMenuChild) { if ($localeMenuChild->getName() == $locale) { $localeMenuChild->setCurrent(true); } if ($localeMenuChild->getName() == 'default' && $locale == null) { $localeMenuChild->setCurrent(true); } } } $site = $this->get('doctrine')->getRepository('OpiferCmsBundle:Site')->findOneBy([]); $menu->setSite($site); $form = $this->createForm('admin_menu', $menu); $form->handleRequest($request); if ($form->isValid()) { $em->persist($menu); $em->flush(); return $this->redirect($this->generateUrl('opifer_cms_menu_index', ['siteId' => $menu->getSite()->getId(), 'locale' => $locale])); } return $this->render('OpiferCmsBundle:Menu:edit.html.twig', ['menu' => $menu, 'localeMenu' => isset($localeMenu) ? $localeMenu : '', 'form' => $form->createView()]); }