コード例 #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()));
 }
コード例 #2
0
ファイル: PoolTest.php プロジェクト: Opifer/Cms
 public function testAddProvider()
 {
     $provider = m::mock('Opifer\\MediaBundle\\Provider\\ProviderInterface');
     $pool = new Pool();
     $pool->addProvider($provider, 'provider');
     $providers = $pool->getProviders();
     $this->assertArrayHasKey('provider', $providers);
     $this->assertInstanceOf('Opifer\\MediaBundle\\Provider\\ProviderInterface', $providers['provider']);
 }
コード例 #3
0
ファイル: MediaPickerType.php プロジェクト: dzoke/Cms
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars = array_replace($view->vars, ['providers' => $this->providerPool->getProviders()]);
 }
コード例 #4
0
ファイル: MediaExtension.php プロジェクト: Opifer/Cms
 /**
  * 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');
 }