Skip to content

Commit

Permalink
Changed maxFileSize value type to float
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Oct 31, 2023
1 parent 4ced86d commit de43e90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lib/FieldType/Image/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Type extends FieldType implements TranslationContainerInterface
protected $validatorConfigurationSchema = [
'FileSizeValidator' => [
'maxFileSize' => [
'type' => 'int',
'type' => 'float',
'default' => null,
],
],
Expand Down Expand Up @@ -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]"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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,
Expand Down

0 comments on commit de43e90

Please sign in to comment.