diff --git a/Form/Type/AcbFileType.php b/Form/Type/AcbFileType.php index 93c1fd8..e20c9c5 100644 --- a/Form/Type/AcbFileType.php +++ b/Form/Type/AcbFileType.php @@ -36,7 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('title', TextType::class, [ 'label' => 'field_type.file.title', - 'constraints' => [ + 'constraints' => !$options['required'] ? [] : [ new NotBlank(null, null, null, null, $options['validation_groups']), ], ]) @@ -97,8 +97,8 @@ public function updateForm(FormInterface $form, $data, $options) $form ->add('file', FileType::class, array_merge([ 'label' => 'field_type.file.file', - 'required' => !$isFileUploaded, - ], $isFileUploaded ? [] : [ + 'required' => !$isFileUploaded && $options['required'], + ], $isFileUploaded || !$options['required'] ? [] : [ 'constraints' => [ new NotBlank(null, null, null, null, $options['validation_groups']), ], @@ -111,7 +111,9 @@ public function updateForm(FormInterface $form, $data, $options) 'label' => 'field_type.file.delete', 'required' => false, ]); - $form->add('src', HiddenType::class); + $form->add('src', HiddenType::class, [ + 'required' => $options['required'], + ]); } }