コード例 #1
0
 /**
  * @param Menu $menu
  * @return array
  */
 public function menuTopLevelItems(Menu $menu)
 {
     $items = [];
     /** @var MenuItem $item */
     foreach ($menu->getItems() as $item) {
         if (!$item->getParent()) {
             $items[] = $item;
         }
     }
     return $items;
 }
コード例 #2
0
 public function orderSortable(Menu $menu, array $array)
 {
     $map = [];
     /** @var MenuItem $item */
     foreach ($menu->getItems() as $item) {
         $map[$item->getId()] = $item;
     }
     foreach ($array as $ord => $order) {
         $this->_orderSortable($map, $order, $ord);
     }
     $this->manager->save($menu);
 }
コード例 #3
0
 public function chooseRouteAction(Menu $menu, $parentId, Request $request)
 {
     $item = new MenuItem();
     $form = $this->createForm(RouteChoiceType::class, $item);
     $form->handleRequest($request);
     if ($form->isValid()) {
         return $this->redirectToRoute('wucdbm_menu_builder_client_menu_item_add', ['id' => $menu->getId(), 'routeId' => $item->getRoute()->getId(), 'parentId' => $parentId]);
     }
     $data = ['menu' => $menu, 'parentId' => $parentId, 'form' => $form->createView()];
     if ($request->isXmlHttpRequest()) {
         return $this->json(['mfp' => $this->renderView('@WucdbmMenuBuilderClient/Menu/Item/route_choice/choose_popup.html.twig', $data)]);
     }
     return $this->render('@WucdbmMenuBuilderClient/Menu/Item/route_choice/choose.html.twig', $data);
 }
コード例 #4
0
 public function remove(Menu $menu)
 {
     $em = $this->getEntityManager();
     $conn = $em->getConnection();
     $conn->beginTransaction();
     try {
         foreach ($menu->getItems() as $item) {
             foreach ($item->getParameters() as $parameter) {
                 $em->remove($parameter);
             }
             $em->remove($item);
         }
         $em->remove($menu);
         $em->flush();
         $conn->commit();
     } catch (\Exception $e) {
         $conn->rollBack();
         throw $e;
     }
 }
コード例 #5
0
 public function removeAction(Menu $menu, Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         if ($menu->getIsSystem()) {
             return $this->json(['witter' => ['title' => sprintf('Failed removing %s', $menu->getName()), 'text' => sprintf('You can not delete "%s" because it is a System menu and doing so will break the application.', $menu->getName())]]);
         }
         $isConfirmed = $request->request->get('is_confirmed');
         if ($isConfirmed) {
             $menuRepository = $this->container->get('wucdbm_menu_builder.repo.menus');
             $menuRepository->remove($menu);
             return $this->json(['redirect' => $this->generateUrl('wucdbm_menu_builder_client_menu_list')]);
         }
         return $this->json(['witter' => ['title' => 'You must confirm this action', 'text' => 'You must confirm first in order to delete this Menu']]);
     }
     $referer = $request->headers->get('Referer');
     if ($referer) {
         return $this->redirect($referer);
     }
     return $this->redirectToRoute('wucdbm_menu_builder_client_menu_list');
 }