From de43e900733cb0896ca850e58e80428a6f459f89 Mon Sep 17 00:00:00 2001 From: Tomasz Kryszan Date: Tue, 31 Oct 2023 13:11:35 +0100 Subject: [PATCH] Changed maxFileSize value type to float --- src/lib/FieldType/Image/Type.php | 6 +++--- .../Legacy/Content/FieldValue/Converter/ImageConverter.php | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/FieldType/Image/Type.php b/src/lib/FieldType/Image/Type.php index 76bf759125..1a19738adc 100644 --- a/src/lib/FieldType/Image/Type.php +++ b/src/lib/FieldType/Image/Type.php @@ -24,7 +24,7 @@ class Type extends FieldType implements TranslationContainerInterface protected $validatorConfigurationSchema = [ 'FileSizeValidator' => [ 'maxFileSize' => [ - 'type' => 'int', + 'type' => 'float', 'default' => null, ], ], @@ -233,14 +233,14 @@ public function validateValidatorConfiguration($validatorConfiguration) ); break; } - if (!is_int($parameters['maxFileSize']) && $parameters['maxFileSize'] !== null) { + if (!is_float($parameters['maxFileSize']) && $parameters['maxFileSize'] !== null) { $validationErrors[] = new ValidationError( 'Validator %validator% expects parameter %parameter% to be of %type%.', null, [ '%validator%' => $validatorIdentifier, '%parameter%' => 'maxFileSize', - '%type%' => 'integer', + '%type%' => 'float', ], "[$validatorIdentifier][maxFileSize]" ); diff --git a/src/lib/Persistence/Legacy/Content/FieldValue/Converter/ImageConverter.php b/src/lib/Persistence/Legacy/Content/FieldValue/Converter/ImageConverter.php index 80989af520..2da5a66c2b 100644 --- a/src/lib/Persistence/Legacy/Content/FieldValue/Converter/ImageConverter.php +++ b/src/lib/Persistence/Legacy/Content/FieldValue/Converter/ImageConverter.php @@ -183,7 +183,9 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField { $validators = $fieldDef->fieldTypeConstraints->validators; - $storageDef->dataInt1 = $validators['FileSizeValidator']['maxFileSize'] ?? 0; + $storageDef->dataInt1 = isset($validators['FileSizeValidator']['maxFileSize']) + ? $validators['FileSizeValidator']['maxFileSize'] * 1024 + : 0; $storageDef->dataInt2 = (int)($validators['AlternativeTextValidator']['required'] ?? 0); } @@ -193,7 +195,7 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin [ 'validators' => [ 'FileSizeValidator' => [ - 'maxFileSize' => $storageDef->dataInt1 !== 0 ? $storageDef->dataInt1 : null, + 'maxFileSize' => $storageDef->dataInt1 !== 0 ? $storageDef->dataInt1 / 1024 : null, ], 'AlternativeTextValidator' => [ 'required' => (bool)$storageDef->dataInt2,