Ejemplo n.º 1
0
 /**
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     // getSubscribedEvents doesn't seem to support parent classes
     if (!$event->getObject() instanceof MediaInterface) {
         return;
     }
     $provider = $this->pool->getProvider($event->getObject()->getProvider());
     if ($provider->getName() == 'image') {
         $reference = $provider->getThumb($event->getObject());
         $groups = $event->getContext()->attributes->get('groups');
         if (!$groups instanceof None && in_array('detail', $groups->get())) {
             $filters = array_keys($this->filterConfig->all());
         } else {
             $filters = ['medialibrary'];
         }
         $variants = [];
         foreach ($filters as $filter) {
             if ($event->getObject()->getContentType() == 'image/svg+xml') {
                 $variants[$filter] = $provider->getUrl($event->getObject());
             } else {
                 $variants[$filter] = $this->cacheManager->getBrowserPath($reference, $filter);
             }
         }
         $event->getVisitor()->addData('images', $variants);
     }
     $event->getVisitor()->addData('original', $provider->getUrl($event->getObject()));
 }
Ejemplo n.º 2
0
 /**
  * Gets the source url of a media item
  *
  * @param Media $media
  *
  * @return \Twig_Markup
  */
 public function sourceUrl($media)
 {
     return new \Twig_Markup($this->pool->getProvider($media->getProvider())->getUrl($media), 'utf8');
 }