diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 76e199f..368a80c 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -5,6 +5,7 @@ * Defines a "managed_file" Form API field and a "file" field for Field module. */ +use Drupal\file\FileInterface; use Drupal\file\Entity\File; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityStorageControllerInterface; @@ -424,7 +425,7 @@ function file_validate_is_image(File $file) { * Non-image files will be ignored. If an image toolkit is available, the image * will be scaled to fit within the desired maximum dimensions. * - * @param Drupal\file\Entity\File $file + * @param \Drupal\file\FileInterface $file * A file entity. This function may resize the file affecting its size. * @param string $maximum_dimensions * An optional string in the form WIDTHxHEIGHT e.g. '640x480' or '85x85'. If @@ -440,13 +441,13 @@ function file_validate_is_image(File $file) { * * @see hook_file_validate() */ -function file_validate_image_dimensions(File $file, $maximum_dimensions = '', $minimum_dimensions = '') { +function file_validate_image_dimensions(FileInterface $file, $maximum_dimensions = '', $minimum_dimensions = '') { $errors = array(); - // Check first that the file is an image. - /** @var $image_factory Drupal\Core\Image\ImageFactory */ + /** @var $image_factory \Drupal\Core\Image\ImageFactory */ $image_factory = \Drupal::service('image.factory'); $image = $image_factory->get($file->getFileUri()); + // First check that the file is an image. if ($image->getExtension()) { if ($maximum_dimensions) { // Check that it is smaller than the given dimensions. @@ -460,15 +461,15 @@ function file_validate_image_dimensions(File $file, $maximum_dimensions = '', $m drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions))); } else { - $errors[] = t('The image is too large and saving a resized version failed.'); + $errors[] = t('The image exceeds the maximum allowed dimensions and saving a resized version failed.'); } } else { - $errors[] = t('The image is too large but resizing failed.'); + $errors[] = t('The image exceeds the maximum allowed dimensions and resizing it failed.'); } } else { - $errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions)); + $errors[] = t('The image exceeds the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)); } } } @@ -787,7 +788,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination $uploaded_files = $_FILES; if (!is_array($uploaded_files['files']['name'][$form_field_name])) { foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $value) - $uploaded_files['files'][$value][$form_field_name] = array($uploaded_files['files'][$value][$form_field_name]); + $uploaded_files['files'][$value][$form_field_name] = array($uploaded_files['files'][$value][$form_field_name]); } $files = array(); @@ -815,7 +816,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination break; } - // Unknown error + // Unknown error default: drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $name)), 'error'); $files[$i] = FALSE;