src/Flowcode/ShopBundle/Controller/AdminProductController.php
/**
     * Creates a new Media entity.
     *
     * @Route("/{id}/creategalleryitem", name="admin_product_gallery_item_create")
     * @Method("POST")
     * @Template("FlowcodeShopBundle:AdminProduct:gallery_add_item.html.twig")
     */
Creates a new Media entity.
Creates a new Media entity .
public function createGalleryItemAction(Product $product, Request $request)
    {
        $entity = new GalleryItem();
        $form = $this->createForm($this->get("amulen.shop.form.product.gallery"), $entity, array(
            'action' => $this->generateUrl('admin_product_gallery_item_create', array('id' => $product->getId())),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Create'));
        $form->handleRequest($request);
        if ($form->isValid()) {
            $gallery = $product->getMediaGallery();
            $gallery->addGalleryItem($entity);
            $entity->setGallery($gallery);
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();
            return $this->redirect($this->generateUrl('admin_product_show', array('id' => $product->getId())));
        }
        return array(
            'entity' => $entity,
            'product' => $product,
            'form' => $form->createView(),
        );
    }
public function createGalleryItemAction ( Product $ product , Request $ request ) { $ entity = new GalleryItem ( ) ; $ form = $ this -> createForm ( $ this -> get ( " amulen.shop.form.product.gallery " ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'admin_product_gallery_item_create' , array ( 'id' => $ product -> getId ( ) ) ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ gallery = $ product -> getMediaGallery ( ) ; $ gallery -> addGalleryItem ( $ entity ) ; $ entity -> setGallery ( $ gallery ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_product_show' , array ( 'id' => $ product -> getId ( ) ) ) ) ; } return array ( 'entity' => $ entity , 'product' => $ product , 'form' => $ form -> createView ( ) , ) ; }
Creates a new Media entity.
Creates a new Media entity .