/** * {@inheritdoc} */ public function generatePrivateUrl(MediaProviderInterface $provider, MediaInterface $media, $format) { if ($format != 'reference') { throw new \RuntimeException('No private url for LiipImagineThumbnail'); } $path = $provider->getReferenceImage($media); return $path; }
/** * {@inheritdoc} */ public function reverseTransform($media) { if (!$media instanceof MediaInterface) { return $media; } $this->provider->transform($media); return $media; }
/** * {@inheritdoc} */ public function delete(MediaProviderInterface $provider, MediaInterface $media) { // delete the differents formats foreach ($provider->getFormats() as $format => $definition) { $path = $provider->generatePrivateUrl($media, $format); if ($provider->getFilesystem()->has($path)) { $provider->getFilesystem()->delete($path); } } }
/** * {@inheritdoc} */ public function delete(MediaProviderInterface $provider, MediaInterface $media, $formats = null) { if (is_null($formats)) { $formats = array_keys($provider->getFormats()); } elseif (is_string($formats)) { $formats = array($formats); } if (!is_array($formats)) { throw new \InvalidArgumentException('"Formats" argument should be string or array'); } foreach ($formats as $format) { $path = $provider->generatePrivateUrl($media, $format); if ($path && $provider->getFilesystem()->has($path)) { $provider->getFilesystem()->delete($path); } } }
/** * @param MediaInterface $media * @param MediaProviderInterface $provider * @param string $context * @param string $format * * @return bool */ protected function processMedia(MediaInterface $media, MediaProviderInterface $provider, $context, $format) { $this->log('Deleting thumbs for ' . $media->getName() . ' - ' . $media->getId()); try { if ($format === $context . '_all') { $format = null; } $provider->removeThumbnails($media, $format); } catch (\Exception $e) { $this->log(sprintf('<error>Unable to remove thumbnails, media: %s - %s </error>', $media->getId(), $e->getMessage())); return false; } return true; }
/** * Write a medium, this method is used by both POST and PUT action methods. * * @param Request $request * @param MediaInterface $media * @param MediaProviderInterface $provider * * @return View|FormInterface */ protected function handleWriteMedium(Request $request, MediaInterface $media, MediaProviderInterface $provider) { $form = $this->formFactory->createNamed(null, 'sonata_media_api_form_media', $media, array('provider_name' => $provider->getName(), 'csrf_protection' => false)); $form->handleRequest($request); if ($form->isValid()) { $media = $form->getData(); $this->mediaManager->save($media); $view = FOSRestView::create($media); $serializationContext = SerializationContext::create(); $serializationContext->setGroups(array('sonata_api_read')); $serializationContext->enableMaxDepthChecks(); $view->setSerializationContext($serializationContext); return $view; } return $form; }
/** * @param FormMapper $formMapper * @param MediaProviderInterface $provider */ protected function buildEditForm(FormMapper $formMapper, MediaProviderInterface $provider) { $provider->buildEditForm($formMapper); if ($formMapper->get('binaryContent')) { /** @var \Symfony\Component\Form\FormBuilder $formBuilder */ $field = $formMapper->get('binaryContent'); $options = $field->getOptions(); $label = "form.label_binary_content_new"; $providerName = $provider->getName(); if ($providerName == 'sonata.media.provider.image' || $providerName == 'sonata.media.provider.youtube') { $previewImageLabel = "form.label_image"; $label = "form.label_binary_content_image_new"; if ($providerName == 'sonata.media.provider.youtube') { $previewImageLabel = 'form.label_current_video'; $label = "form.label_binary_content_youtube_new"; } $formMapper->remove('binaryContent'); $formMapper->add('self', 'networking_type_media_preview', array('required' => false, 'label' => $previewImageLabel, 'provider' => $providerName)); } $options['label'] = $label; $formMapper->add('binaryContent', $field->getType()->getName(), $options); } }
/** * @param MediaInterface $media * @param MediaProviderInterface $provider * * @return bool */ protected function processMedia($media, $provider) { $this->log('Generating thumbs for ' . $media->getName() . ' - ' . $media->getId()); try { $provider->removeThumbnails($media); } catch (\Exception $e) { $this->log(sprintf('<error>Unable to remove old thumbnails, media: %s - %s </error>', $media->getId(), $e->getMessage())); return false; } try { $provider->generateThumbnails($media); } catch (\Exception $e) { $this->log(sprintf('<error>Unable to generate new thumbnails, media: %s - %s </error>', $media->getId(), $e->getMessage())); return false; } return true; }