diff -u b/core/modules/file/file.module b/core/modules/file/file.module --- b/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -294,8 +294,10 @@ // Allow a mixed result of messages and errors so validators can // provide messages to be shown only if there are no errors. - if (array_key_exists('errors', $result)) { - $errors = array_merge($errors, $result['errors']); + if (array_intersect(['errors', 'messages'], array_keys($result))) { + if (array_key_exists('errors', $result)) { + $errors = array_merge($errors, $result['errors']); + } if (array_key_exists('messages', $result)) { $messages = array_merge($messages, $result['messages']); } only in patch2: unchanged: --- a/core/modules/file/tests/src/Kernel/ValidatorTest.php +++ b/core/modules/file/tests/src/Kernel/ValidatorTest.php @@ -70,20 +70,20 @@ function testFileValidateIsImage() { */ function testFileValidateImageResolution() { // Non-images. - $errors = file_validate_image_resolution($this->nonImage); - $this->assertEqual(count($errors), 0, 'Should not get any errors for a non-image file.', 'File'); - $errors = file_validate_image_resolution($this->nonImage, '50x50', '100x100'); - $this->assertEqual(count($errors), 0, 'Do not check the resolution on non files.', 'File'); + $result = file_validate_image_resolution($this->nonImage); + $this->assertEqual(count($result['errors']), 0, 'Should not get any errors for a non-image file.', 'File'); + $result = file_validate_image_resolution($this->nonImage, '50x50', '100x100'); + $this->assertEqual(count($result['errors']), 0, 'Do not check the resolution on non files.', 'File'); // Minimum size. - $errors = file_validate_image_resolution($this->image); - $this->assertEqual(count($errors), 0, 'No errors for an image when there is no minimum or maximum resolution.', 'File'); - $errors = file_validate_image_resolution($this->image, 0, '200x1'); - $this->assertEqual(count($errors), 1, 'Got an error for an image that was not wide enough.', 'File'); - $errors = file_validate_image_resolution($this->image, 0, '1x200'); - $this->assertEqual(count($errors), 1, 'Got an error for an image that was not tall enough.', 'File'); - $errors = file_validate_image_resolution($this->image, 0, '200x200'); - $this->assertEqual(count($errors), 1, 'Small images report an error.', 'File'); + $result = file_validate_image_resolution($this->image); + $this->assertEqual(count($result['errors']), 0, 'No errors for an image when there is no minimum or maximum resolution.', 'File'); + $result = file_validate_image_resolution($this->image, 0, '200x1'); + $this->assertEqual(count($result['errors']), 1, 'Got an error for an image that was not wide enough.', 'File'); + $result = file_validate_image_resolution($this->image, 0, '1x200'); + $this->assertEqual(count($result['errors']), 1, 'Got an error for an image that was not tall enough.', 'File'); + $result = file_validate_image_resolution($this->image, 0, '200x200'); + $this->assertEqual(count($result['errors']), 1, 'Small images report an error.', 'File'); // Maximum size. if ($this->container->get('image.factory')->getToolkitId()) { @@ -91,8 +91,8 @@ function testFileValidateImageResolution() { copy('core/misc/druplicon.png', 'temporary://druplicon.png'); $this->image->setFileUri('temporary://druplicon.png'); - $errors = file_validate_image_resolution($this->image, '10x5'); - $this->assertEqual(count($errors), 0, 'No errors should be reported when an oversized image can be scaled down.', 'File'); + $result = file_validate_image_resolution($this->image, '10x5'); + $this->assertEqual(count($result['errors']), 0, 'No errors should be reported when an oversized image can be scaled down.', 'File'); $image = $this->container->get('image.factory')->get($this->image->getFileUri()); $this->assertTrue($image->getWidth() <= 10, 'Image scaled to correct width.', 'File'); @@ -101,15 +101,15 @@ function testFileValidateImageResolution() { // Once again, now with negative width and height to force an error. copy('core/misc/druplicon.png', 'temporary://druplicon.png'); $this->image->setFileUri('temporary://druplicon.png'); - $errors = file_validate_image_resolution($this->image, '-10x-5'); - $this->assertEqual(count($errors), 1, 'An error reported for an oversized image that can not be scaled down.', 'File'); + $result = file_validate_image_resolution($this->image, '-10x-5'); + $this->assertEqual(count($result['errors']), 1, 'An error reported for an oversized image that can not be scaled down.', 'File'); drupal_unlink('temporary://druplicon.png'); } else { // TODO: should check that the error is returned if no toolkit is available. - $errors = file_validate_image_resolution($this->image, '5x10'); - $this->assertEqual(count($errors), 1, 'Oversize images that cannot be scaled get an error.', 'File'); + $result = file_validate_image_resolution($this->image, '5x10'); + $this->assertEqual(count($result['errors']), 1, 'Oversize images that cannot be scaled get an error.', 'File'); } }