Skip to content

Commit

Permalink
IBX-7502: Moved Image asset file validation to field type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jan 10, 2024
1 parent d54af6d commit f36c784
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/lib/Form/Type/FieldType/ImageAssetFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\Mime\MimeTypesInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;

class ImageAssetFieldType extends AbstractType
{
Expand Down Expand Up @@ -79,11 +78,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
[
'label' => /** @Desc("File") */ 'content.field_type.binary_base.file',
'required' => $options['required'],
'constraints' => [
new Assert\File([
'maxSize' => $this->getMaxFileSize(),
]),
],
'mapped' => false,
]
)
Expand Down Expand Up @@ -141,12 +135,7 @@ private function getMaxFileSize(): float
->getAssetFieldDefinition()
->getValidatorConfiguration();

$maxFileSize = $validatorConfiguration['FileSizeValidator']['maxFileSize'];
if ($maxFileSize > 0) {
return (float)min($maxFileSize * 1024 * 1024, $this->maxUploadSize->get());
}

return (float)$this->maxUploadSize->get();
return (float)$validatorConfiguration['FileSizeValidator']['maxFileSize'] * 1024 * 1024;
}

/**
Expand Down

0 comments on commit f36c784

Please sign in to comment.