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

get() public method

Returns media with a given collection and/or ids and/or limit if no arguments passed returns all media.
public get ( string $locale, array $filter = [], integer $limit = null, integer $offset = null ) : Media[]
$locale string the locale which the object will be returned
$filter array collection, ids, types
$limit integer to limit the output
$offset integer to offset the output
return Sulu\Bundle\MediaBundle\Api\Media[]
    public function get($locale, $filter = [], $limit = null, $offset = null);

Usage Example

 /**
  * Returns the url for the image.
  *
  * @param $data
  * @param $locale
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  */
 private function getImageUrl($data, $locale)
 {
     // new structures will container an instance of MediaSelectionContainer
     if ($data instanceof MediaSelectionContainer) {
         $medias = $data->getData('de');
         // old ones an array ...
     } else {
         if (!isset($data['ids'])) {
             throw new \RuntimeException(sprintf('Was expecting media value to contain array key "ids", got: "%s"', print_r($data, true)));
         }
         $medias = $this->mediaManager->get($locale, ['ids' => $data['ids']]);
     }
     // no media, no thumbnail URL
     if (!$medias) {
         return;
     }
     $media = current($medias);
     if (!$media) {
         return;
     }
     $formats = $media->getThumbnails();
     if (!isset($formats[$this->searchImageFormat])) {
         throw new \InvalidArgumentException(sprintf('Search image format "%s" is not known', $this->searchImageFormat));
     }
     return $formats[$this->searchImageFormat];
 }