Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if (!$media->getBinaryContent()) {
         return;
     }
     if (preg_match("/(?<=v(\\=|\\/))([-a-zA-Z0-9_]+)|(?<=youtu\\.be\\/)([-a-zA-Z0-9_]+)/", $media->getBinaryContent(), $matches)) {
         $media->setBinaryContent($matches[2]);
     }
 }
Example #2
0
 /**
  * @throws \RuntimeException
  *
  * @param \Sonata\MediaBundle\Model\MediaInterface $media
  *
  * @return
  */
 protected function fixBinaryContent(MediaInterface $media)
 {
     if ($media->getBinaryContent() === null) {
         return;
     }
     // if the binary content is a filename => convert to a valid File
     if (!$media->getBinaryContent() instanceof File) {
         if (!is_file($media->getBinaryContent())) {
             throw new \RuntimeException('The file does not exist : ' . $media->getBinaryContent());
         }
         $binaryContent = new File($media->getBinaryContent());
         $media->setBinaryContent($binaryContent);
     }
 }