Skip to content
Snippets Groups Projects

Resolve #3372385 "11.x"

Closed Rolando Payán Mosqueda requested to merge issue/drupal-3372385:3372385-11.x into 11.x
5 files
+ 66
1
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -193,7 +193,7 @@ public function upload(Request $request) {
$file->setFilename($prepared_filename);
$file->setMimeType($this->mimeTypeGuesser->guessMimeType($prepared_filename));
$file->setFileUri($file_uri);
$file->setFileUri($temp_file_path);
$file->setSize(@filesize($temp_file_path));
$violations = $this->validate($file, $validators);
@@ -208,6 +208,7 @@ public function upload(Request $request) {
throw new HttpException(500, 'Temporary file could not be moved to file location');
}
$file->setFileUri($file_uri);
$file->save();
$this->lock->release($lock_id);
@@ -257,6 +258,15 @@ protected function validate(FileInterface $file, array $validators) {
// 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 (in_array('uri', $violations->getFieldNames(), TRUE)) {
$violations->filterByFields(array_diff($fieldNames, ['uri']));
}
// Validate the file based on the field definition configuration.
$violations->addAll($this->fileValidator->validate($file, $validators));
Loading