diff --git a/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php b/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php index d7ef7f7e4e1..72d71ef54bf 100644 --- a/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php +++ b/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php @@ -210,6 +210,16 @@ public function upload(Request $request) { } $file->setFileUri($file_uri); + $violations = $file->validate(); + + // Remove violations of inaccessible fields as they cannot stem from our + // changes. + $violations->filterByFieldAccess(); + + if ($violations->count() > 0) { + throw new UnprocessableEntityHttpException($violations->__toString()); + } + $file->save(); $this->lock->release($lock_id); @@ -253,23 +263,7 @@ public function imageUploadEnabledAccess(Editor $editor) { * The list of constraint violations, if any. */ protected function validate(FileInterface $file, array $validators) { - $violations = $file->validate(); - - // Remove violations of inaccessible fields as they cannot stem from our - // changes. - $violations->filterByFieldAccess(); - - // Prevent validation of the URI field because the file validation handler - // expects it to have a schema, and it does not have one yet. - $fieldNames = $violations->getFieldNames(); - - // The filterByFields() method doesn't work with an empty array. - if ($fieldNames === ['uri']) { - $violations = new EntityConstraintViolationList($file); - } - else { - $violations->filterByFields(array_diff($fieldNames, ['uri'])); - } + $violations = new EntityConstraintViolationList($file); // Validate the file based on the field definition configuration. $violations->addAll($this->fileValidator->validate($file, $validators));