src/PN/Bundle/ProductBundle/Controller/Administration/CategoryController.php
/**
     * Displays a form to edit an existing category entity.
     *
     * @Route("/{id}/edit", name="category_edit", methods={"GET", "POST"})
     */
Displays a form to edit an existing category entity.
Displays a form to edit an existing category entity .
public function editAction(Request $request, Category $category)
    {
        $this->denyAccessUnlessGranted('ROLE_ADMIN');
        $em = $this->getDoctrine()->getManager();
        $form = $this->createForm(CategoryType::class, $category);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $userName = $this->get('user')->getUserName();
            $category->setModifiedBy($userName);
            $em->flush();
            $uploadImage = $this->uploadImage($request, $form, $category);
            if ($uploadImage != false) {
                $this->addFlash('success', 'Successfully updated');
                return $this->redirectToRoute('category_edit', array('id' => $category->getId()));
            }
            $this->addFlash('success', 'Successfully saved');
            if ($request->request->get("action") == "saveAndNext") {
                return $this->redirectToRoute('attribute_index', ["id" => $category->getId()]);
            }
            if ($category->getParent()) {
                return $this->redirectToRoute('category_index', ['parentCategory' => $category->getParent()->getId()]);
            }
            return $this->redirectToRoute('category_index');
        }
        $categoryParents = $this->get(CategoryService::class)->parentsByChildId($category->getParent());
        return $this->render('product/admin/category/edit.html.twig', array(
            'category' => $category,
            'categoryParents' => $categoryParents,
            'form' => $form->createView(),
        ));
    }
public function editAction ( Request $ request , Category $ category ) { $ this -> denyAccessUnlessGranted ( 'ROLE_ADMIN' ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ form = $ this -> createForm ( CategoryType :: class , $ category ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ userName = $ this -> get ( 'user' ) -> getUserName ( ) ; $ category -> setModifiedBy ( $ userName ) ; $ em -> flush ( ) ; $ uploadImage = $ this -> uploadImage ( $ request , $ form , $ category ) ; if ( $ uploadImage != false ) { $ this -> addFlash ( 'success' , 'Successfully updated' ) ; return $ this -> redirectToRoute ( 'category_edit' , array ( 'id' => $ category -> getId ( ) ) ) ; } $ this -> addFlash ( 'success' , 'Successfully saved' ) ; if ( $ request -> request -> get ( " action " ) == " saveAndNext " ) { return $ this -> redirectToRoute ( 'attribute_index' , [ " id " => $ category -> getId ( ) ] ) ; } if ( $ category -> getParent ( ) ) { return $ this -> redirectToRoute ( 'category_index' , [ 'parentCategory' => $ category -> getParent ( ) -> getId ( ) ] ) ; } return $ this -> redirectToRoute ( 'category_index' ) ; } $ categoryParents = $ this -> get ( CategoryService :: class ) -> parentsByChildId ( $ category -> getParent ( ) ) ; return $ this -> render ( 'product/admin/category/edit.html.twig' , array ( 'category' => $ category , 'categoryParents' => $ categoryParents , 'form' => $ form -> createView ( ) , ) ) ; }
Displays a form to edit an existing category entity.
Displays a form to edit an existing category entity .