From eb767f06cfdcd00371769ab78e3cf4c8172320d4 Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Mon, 4 Mar 2024 10:04:18 +0100 Subject: [PATCH] fix compatibily error in enhanced image form mapper --- .../FieldType/EnhancedImage/FormMapper.php | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/src/lib/FieldType/EnhancedImage/FormMapper.php b/src/lib/FieldType/EnhancedImage/FormMapper.php index f4f11e0..7ae3437 100644 --- a/src/lib/FieldType/EnhancedImage/FormMapper.php +++ b/src/lib/FieldType/EnhancedImage/FormMapper.php @@ -14,25 +14,72 @@ namespace Novactive\EzEnhancedImageAsset\FieldType\EnhancedImage; -use Ibexa\AdminUi\FieldType\Mapper\ImageFormMapper; +use Ibexa\AdminUi\Form\Data\FieldDefinitionData; +use Ibexa\ContentForms\ConfigResolver\MaxUploadSize; use Ibexa\Contracts\ContentForms\Data\Content\FieldData; use Ibexa\Contracts\ContentForms\FieldType\FieldValueFormMapperInterface; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\FieldTypeService; use Novactive\EzEnhancedImageAsset\Form\Type\FieldType\EnhancedImageFieldType; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\FormInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints\Range; -class FormMapper extends ImageFormMapper implements FieldValueFormMapperInterface +class FormMapper implements FieldValueFormMapperInterface { /** @var FieldTypeService */ private $fieldTypeService; + /** @var \Ibexa\ContentForms\ConfigResolver\MaxUploadSize */ + private $maxUploadSize; + + public function __construct(FieldTypeService $fieldTypeService, MaxUploadSize $maxUploadSize) + { + $this->fieldTypeService = $fieldTypeService; + $this->maxUploadSize = $maxUploadSize; + } + + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void + { + $isTranslation = $data->contentTypeData->languageCode !== $data->contentTypeData->mainLanguageCode; + $fieldDefinitionForm + ->add('maxSize', IntegerType::class, [ + 'required' => false, + 'property_path' => 'validatorConfiguration[FileSizeValidator][maxFileSize]', + 'label' => /* @Desc("Maximum file size (MB)") */ 'field_definition.ezimage.max_file_size', + 'constraints' => [ + new Range([ + 'min' => 0, + 'max' => $this->maxUploadSize->get(MaxUploadSize::MEGABYTES), + ]), + ], + 'attr' => [ + 'min' => 0, + 'max' => $this->maxUploadSize->get(MaxUploadSize::MEGABYTES), + ], + 'disabled' => $isTranslation, + ]) + ->add('isAlternativeTextRequired', CheckboxType::class, [ + 'required' => false, + 'property_path' => 'validatorConfiguration[AlternativeTextValidator][required]', + 'label' => 'field_definition.ezimage.is_alternative_text_required', + 'disabled' => $isTranslation, + ]); + } + /** - * @required + * Fake method to set the translation domain for the extractor. + * + * @throws \Symfony\Component\OptionsResolver\Exception\AccessException */ - public function setFieldTypeService(FieldTypeService $fieldTypeService): void + public function configureOptions(OptionsResolver $resolver) { - $this->fieldTypeService = $fieldTypeService; + $resolver + ->setDefaults([ + 'translation_domain' => 'content_type', + ]); } /**