Skip to content

Commit

Permalink
Handle non required file
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie-mulard committed May 5, 2023
1 parent dfe2ccb commit 750d536
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Form/Type/AcbFileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
],
])
Expand Down Expand Up @@ -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']),
],
Expand All @@ -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'],
]);
}
}

Expand Down

0 comments on commit 750d536

Please sign in to comment.