Skip to content

Commit

Permalink
Added early return from validation when content is not an asset
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jan 12, 2024
1 parent c5238c5 commit 44d9fbb
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/lib/FieldType/ImageAsset/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,22 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
(int)$fieldValue->destinationContentId
);

if ($this->assetMapper->isAsset($content)) {
$validationError = $this->validateMaxFileSize($content);
if (null !== $validationError) {
$errors[] = $validationError;
}
} else {
$errors[] = new ValidationError(
'Content %type% is not a valid asset target',
null,
[
'%type%' => $content->getContentType()->identifier,
],
'destinationContentId'
);
if (!$this->assetMapper->isAsset($content)) {
return [
new ValidationError(
'Content %type% is not a valid asset target',
null,
[
'%type%' => $content->getContentType()->identifier,
],
'destinationContentId'
),
];
}

$validationError = $this->validateMaxFileSize($content);
if (null !== $validationError) {
$errors[] = $validationError;
}

return $errors;
Expand Down

0 comments on commit 44d9fbb

Please sign in to comment.