Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface::getEntityById PHP Method

getEntityById() public method

Returns a media entity with a given id.
public getEntityById ( integer $id ) : Sulu\Bundle\MediaBundle\Entity\MediaInterface
$id integer
return Sulu\Bundle\MediaBundle\Entity\MediaInterface
    public function getEntityById($id);

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function delete($mediaId, $formatKey)
 {
     if (!isset($this->formats[$formatKey])) {
         throw new FormatNotFoundException($formatKey);
     }
     $media = $this->mediaManager->getEntityById($mediaId);
     $fileVersion = $this->getFileVersionForMedia($media);
     $formatOptions = $fileVersion->getFormatOptions()->get($formatKey);
     if (isset($formatOptions)) {
         $fileVersion->getFormatOptions()->remove($formatKey);
         $fileVersion->increaseSubVersion();
         $this->em->remove($formatOptions);
         $this->em->persist($fileVersion);
         $this->purgeMedia($mediaId, $fileVersion);
     }
 }