/** * @param Request $request * @return Response * @throws BadRequestHttpException */ public function postAction(Request $request) { $contentUid = $request->request->get('content_uid'); $contentType = $request->request->get('content_type', null); $mediaFolderUid = $request->request->get('folder_uid', null); $mediaTitle = $request->request->get('title', 'Untitled media'); if (null === $mediaFolderUid) { $mediaFolder = $this->getMediaFolderRepository()->getRoot(); } else { $mediaFolder = $this->getMediaFolderRepository()->find($mediaFolderUid); } if (null === $mediaFolder) { throw new NotFoundHttpException('Cannot find a media folder'); } if (null !== ($content = $this->getClassContentManager()->findOneByTypeAndUid($contentType, $contentUid))) { $this->autoCommitContent($content); } $media = new Media(); $media->setContent($content); $media->setTitle($mediaTitle); $media->setMediaFolder($mediaFolder); $this->getEntityManager()->persist($media); $this->getEntityManager()->flush(); return $this->createJsonResponse(null, 201, ['BB-RESOURCE-UID' => $media->getId(), 'Location' => $this->getApplication()->getRouting()->getUrlByRouteName('bb.rest.media.get', ['version' => $request->attributes->get('version'), 'uid' => $media->getId()], '', false)]); }
/** * Create a new media entry * * @param AbstractClassContent $content * @param string $title * * @return void */ protected function createNewMedia(AbstractClassContent $content, $title = '') { $newMedia = new NestedNodeMedia(); $newMedia->setMediaFolder($this->_em->getRepository('BackBee\\NestedNode\\MediaFolder')->getRoot()); $newMedia->setContent($content); $newMedia->setTitle(trim($title . ' [' . $this->request->get('selectedProportion') . ']')); $this->_em->persist($newMedia); $this->_em->flush(); }
/** * @covers BackBee\NestedNode\Media::setMediaFolder * @covers BackBee\NestedNode\Media::getMediaFolder */ public function testSetAndGetMediaFolder() { $media_folder = new MediaFolder('folder'); $this->assertEquals($this->media, $this->media->setMediaFolder($media_folder)); $this->assertEquals($media_folder, $this->media->getMediaFolder()); }