/** * @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())); }
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']); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars = array_replace($view->vars, ['providers' => $this->providerPool->getProviders()]); }
/** * 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'); }