src/PN/Bundle/ProductBundle/Controller/Administration/AttributeController.php
/**
     * Displays a form to create a new Attribute entity.
     *
     * @Route("/new/{id}", name="attribute_new", methods={"GET", "POST"})
     */
Displays a form to create a new Attribute entity.
Displays a form to create a new Attribute entity .
public function newAction(Request $request, Category $category)
    {
        $this->denyAccessUnlessGranted(['ROLE_ADMIN']);
        $attribute = new Attribute();
        $attribute->setCategory($category);
        $form = $this->createForm(AttributeType::class, $attribute);
        $form->handleRequest($request);
        if ($form->isValid() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($attribute);
            $em->flush();
            $this->addFlash('success', 'Successfully saved');
            if (in_array($attribute->getType(), [Attribute::TYPE_DROPDOWN, Attribute::TYPE_CHECKBOX])) {
                return $this->redirectToRoute('attribute_edit', ["id" => $attribute->getId()]);
            }
            return $this->redirectToRoute('attribute_index', ["id" => $category->getId()]);
        }
        $categoryParents = $this->get(CategoryService::class)->parentsByChildId($attribute->getCategory());
        return $this->render("product/admin/attribute/new.html.twig", [
            'attribute' => $attribute,
            'categoryParents' => $categoryParents,
            'form' => $form->createView(),
        ]);
    }
public function newAction ( Request $ request , Category $ category ) { $ this -> denyAccessUnlessGranted ( [ 'ROLE_ADMIN' ] ) ; $ attribute = new Attribute ( ) ; $ attribute -> setCategory ( $ category ) ; $ form = $ this -> createForm ( AttributeType :: class , $ attribute ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ attribute ) ; $ em -> flush ( ) ; $ this -> addFlash ( 'success' , 'Successfully saved' ) ; if ( in_array ( $ attribute -> getType ( ) , [ Attribute :: TYPE_DROPDOWN , Attribute :: TYPE_CHECKBOX ] ) ) { return $ this -> redirectToRoute ( 'attribute_edit' , [ " id " => $ attribute -> getId ( ) ] ) ; } return $ this -> redirectToRoute ( 'attribute_index' , [ " id " => $ category -> getId ( ) ] ) ; } $ categoryParents = $ this -> get ( CategoryService :: class ) -> parentsByChildId ( $ attribute -> getCategory ( ) ) ; return $ this -> render ( " product/admin/attribute/new.html.twig " , [ 'attribute' => $ attribute , 'categoryParents' => $ categoryParents , 'form' => $ form -> createView ( ) , ] ) ; }
Displays a form to create a new Attribute entity.
Displays a form to create a new Attribute entity .