Sulu\Bundle\MediaBundle\Media\Manager\MediaManager::getById PHP Method

getById() public method

public getById ( $id, $locale )
    public function getById($id, $locale)
    {
        $mediaEntity = $this->getEntityById($id);
        return $this->addFormatsAndUrl(new Media($mediaEntity, $locale, null));
    }

Usage Example

示例#1
0
 /**
  * @param Event $event
  * @param $mediaData
  * @param $locale
  * @return bool
  * @throws EventDependencyNotFoundException
  * @throws \Sulu\Bundle\MediaBundle\Media\Exception\MediaNotFoundException
  */
 protected function addMedia(Event $event, $mediaData, $locale)
 {
     $media = $this->mediaManager->getById($mediaData, $locale);
     if (!$media) {
         throw new EventDependencyNotFoundException(MediaManager::ENTITY_NAME_MEDIA, $mediaData);
     }
     $media = $media->getEntity();
     $event->addMedia($media);
     $this->entityManager->persist($media);
     return true;
 }