src/Flowcode/ShopBundle/Controller/AdminProductController.php
/**
     * Creates a new Media entity.
     *
     * @Route("/{product}/media/{type}", name="admin_product_media_create")
     * @Method("POST")
     * @Template("FlowcodeShopBundle:AdminProduct:media_new.html.twig")
     */
Creates a new Media entity.
Creates a new Media entity .
public function createMediaAction(Product $product, Request $request, $type)
    {
        $em = $this->getDoctrine()->getManager();
        $media = new Media();
        $media->setMediaType($type);
        $form = $this->mediaCreateCreateForm($media, $product);
        $form->handleRequest($request);
        if ($type == 'type_video_youtube') {
            if (is_null($product->getVideoGallery())) {
                $gallery = new Gallery();
                $gallery->setName($product->getName());
                $gallery->setEnabled(true);
                $em->persist($gallery);
                $product->setVideoGallery($gallery);
            }
            $gallery = $product->getVideoGallery();
        } else {
            $gallery = $product->getMediaGallery();
        }
        if ($form->isValid()) {
            $galleryItem = new GalleryItem();
            $galleryItem->setGallery($gallery);
            $position = $gallery->getGalleryItems()->count() + 1;
            $galleryItem->setPosition($position);
            $galleryItem->setMedia($media);
            $em = $this->getDoctrine()->getManager();
            $em->persist($media);
            $em->persist($galleryItem);
            $em->flush();
            return $this->redirectToRoute('admin_product_show', array('id' => $product->getId()));
        }
        return array(
            'entity' => $media,
            'product' => $product,
            'form' => $form->createView(),
        );
    }
public function createMediaAction ( Product $ product , Request $ request , $ type ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ media = new Media ( ) ; $ media -> setMediaType ( $ type ) ; $ form = $ this -> mediaCreateCreateForm ( $ media , $ product ) ; $ form -> handleRequest ( $ request ) ; if ( $ type == 'type_video_youtube' ) { if ( is_null ( $ product -> getVideoGallery ( ) ) ) { $ gallery = new Gallery ( ) ; $ gallery -> setName ( $ product -> getName ( ) ) ; $ gallery -> setEnabled ( true ) ; $ em -> persist ( $ gallery ) ; $ product -> setVideoGallery ( $ gallery ) ; } $ gallery = $ product -> getVideoGallery ( ) ; } else { $ gallery = $ product -> getMediaGallery ( ) ; } if ( $ form -> isValid ( ) ) { $ galleryItem = new GalleryItem ( ) ; $ galleryItem -> setGallery ( $ gallery ) ; $ position = $ gallery -> getGalleryItems ( ) -> count ( ) + 1 ; $ galleryItem -> setPosition ( $ position ) ; $ galleryItem -> setMedia ( $ media ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ media ) ; $ em -> persist ( $ galleryItem ) ; $ em -> flush ( ) ; return $ this -> redirectToRoute ( 'admin_product_show' , array ( 'id' => $ product -> getId ( ) ) ) ; } return array ( 'entity' => $ media , 'product' => $ product , 'form' => $ form -> createView ( ) , ) ; }
Creates a new Media entity.
Creates a new Media entity .
/* create media gallery */ /* set video gallery */