public function postFormSubmit(FormSubmitEvent $event) { $post = $event->getPost(); $values = $post->getValueSet()->getValues(); $this->entityManager->refresh($post); foreach ($values as $value) { if ($value instanceof AttachmentValue) { $media = $this->mediaManager->createMedia(); $media->setFile($value->getFile()); $media->setProvider('file'); $value->setAttachment($media); } } $this->entityManager->persist($post); $this->entityManager->flush(); }
/** * @param FormSubmitEvent $event */ public function postFormSubmit(FormSubmitEvent $event) { $post = $event->getPost(); $values = $post->getValueSet()->getValues(); $this->entityManager->refresh($post); foreach ($values as $value) { if ($value instanceof AttachmentValue) { // Avoid saving the attachment when it's empty and not required if (null === $value->getFile() && !$value->getAttribute()->getRequired()) { continue; } $media = $this->mediaManager->createMedia(); $media->setFile($value->getFile()); $media->setProvider('file'); $value->setAttachment($media); } } $this->entityManager->persist($post); $this->entityManager->flush(); }
/** * Save the thumbnail. * * @param MediaInterface $media The Youtube Object * @param string $url * * @return MediaInterface The newly created image */ public function saveThumbnail(MediaInterface $media, $url) { $thumb = $this->mediaManager->createMedia(); $thumb->setStatus(Media::STATUS_HASPARENT)->setName($media->getName() . '_thumb')->setProvider('image'); $filename = '/tmp/' . basename($url); $filesystem = new Filesystem(); $filesystem->dumpFile($filename, file_get_contents($url)); $thumb->temp = $filename; $thumb->setFile(new UploadedFile($filename, basename($url))); $this->mediaManager->save($thumb); return $thumb; }