From d82ce5fcdac27929b243cb891dfc75fe88f5e881 Mon Sep 17 00:00:00 2001 From: Karel Sommer Date: Wed, 31 May 2017 11:00:44 +0200 Subject: [PATCH] fix single upload for using with liip_imagine --- Form/Type/SingleUploadType.php | 38 ++++++++++++++++++++++++++++++++-- Resources/config/services.xml | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Form/Type/SingleUploadType.php b/Form/Type/SingleUploadType.php index 76d6ccd..0705da2 100644 --- a/Form/Type/SingleUploadType.php +++ b/Form/Type/SingleUploadType.php @@ -2,6 +2,7 @@ namespace Admingenerator\FormExtensionsBundle\Form\Type; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; @@ -16,6 +17,23 @@ */ class SingleUploadType extends AbstractType { + + /** + * @var ContainerInterface + */ + private $container; + + /** + * SingleUploadType constructor. + * + * @param ContainerInterface $container + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** * {@inheritdoc} */ @@ -139,7 +157,13 @@ public function getBlockPrefix() */ private function _is_file($file) { - return $file instanceof File && file_exists($file->getPathName()) && !is_dir($file->getPathName()); + if ($file instanceof File) { + if ($this->container->getParameter('admingenerator.form.image_manipulator') !== null) { + return true; + } + return $this->_fileExists($file); + } + return false; } /** @@ -148,7 +172,7 @@ private function _is_file($file) private function _checkFileType($file) { // sanity check - if (!$this->_is_file($file)) return 'inexistent'; + if (!$this->_fileExists($file)) return 'inexistent'; if ($this->_isAudio($file)) return 'audio'; if ($this->_isArchive($file)) return 'archive'; if ($this->_isHTML($file)) return 'html'; @@ -236,4 +260,14 @@ private function _isVideo(File $file) { return (preg_match('/video\/.*/i', $file->getMimeType())); } + + /** + * @param $file + * + * @return bool + */ + private function _fileExists($file) + { + return file_exists($file->getPathName()) && !is_dir($file->getPathName()); + } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 82ab1ee..be4699e 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -103,6 +103,7 @@ +