--- make_file_module_pass-1533236-56.patch 2014-09-15 21:14:58.171570811 +0530 +++ make_file_module_pass-1533236-57.patch 2014-09-15 21:14:36.187571205 +0530 @@ -1,5 +1,5 @@ diff --git a/core/modules/file/css/file.admin.css b/core/modules/file/css/file.admin.css -index 585ea62..d3d9a5f 100644 +index ff87783..80eb78d 100644 --- a/core/modules/file/css/file.admin.css +++ b/core/modules/file/css/file.admin.css @@ -1,4 +1,3 @@ @@ -8,10 +8,19 @@ * @file * Admin stylesheet for file module. diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php -index 23a0291..c58d2bb 100644 +index 23a0291..5bbb7a9 100644 --- a/core/modules/file/file.api.php +++ b/core/modules/file/file.api.php -@@ -18,7 +18,8 @@ +@@ -5,6 +5,8 @@ + * Hooks for file module. + */ + ++use Drupal\file\FileInterface; ++ + /** + * @addtogroup hooks + * @{ +@@ -18,13 +20,14 @@ * * @param \Drupal\file\FileInterface $file * The file entity being validated. @@ -21,6 +30,683 @@ * An array of error messages. If there are no problems with the file return * an empty array. * + * @see file_validate() + */ +-function hook_file_validate(Drupal\file\FileInterface $file) { ++function hook_file_validate(FileInterface $file) { + $errors = array(); + + if (!$file->getFilename()) { +@@ -47,7 +50,7 @@ function hook_file_validate(Drupal\file\FileInterface $file) { + * + * @see file_copy() + */ +-function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { ++function hook_file_copy(FileInterface $file, FileInterface $source) { + // Make sure that the file name starts with the owner's user name. + if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { + $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); +@@ -67,7 +70,7 @@ function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterfa + * + * @see file_move() + */ +-function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { ++function hook_file_move(FileInterface $file, FileInterface $source) { + // Make sure that the file name starts with the owner's user name. + if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { + $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); +diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc +index 3e88433..f863666 100644 +--- a/core/modules/file/file.field.inc ++++ b/core/modules/file/file.field.inc +@@ -20,7 +20,7 @@ + * An associative array containing: + * - element: A render element representing the file. + */ +-function template_preprocess_file_widget(&$variables) { ++function template_preprocess_file_widget(array &$variables) { + $element = $variables['element']; + if (!empty($element['fids']['#value'])) { + // Add the file size after the file name. +@@ -29,7 +29,9 @@ function template_preprocess_file_widget(&$variables) { + } + $variables['element'] = $element; + // The "form-managed-file" class is required for proper Ajax functionality. +- $variables['attributes'] = array('class' => array('file-widget', 'form-managed-file', 'clearfix')); ++ $variables['attributes'] = array( ++ 'class' => array('file-widget', 'form-managed-file', 'clearfix'), ++ ); + } + + /** +@@ -41,7 +43,7 @@ function template_preprocess_file_widget(&$variables) { + * An associative array containing: + * - element: A render element representing the widgets. + */ +-function template_preprocess_file_widget_multiple(&$variables) { ++function template_preprocess_file_widget_multiple(array &$variables) { + $element = $variables['element']; + + // Special ID and classes for draggable tables. +@@ -160,7 +162,7 @@ function template_preprocess_file_widget_multiple(&$variables) { + * - upload_validators: An array of upload validators as used in + * $element['#upload_validators']. + */ +-function template_preprocess_file_upload_help(&$variables) { ++function template_preprocess_file_upload_help(array &$variables) { + $description = $variables['description']; + $upload_validators = $variables['upload_validators']; + $cardinality = $variables['cardinality']; +diff --git a/core/modules/file/file.install b/core/modules/file/file.install +index 8d13c03..dc64477 100644 +--- a/core/modules/file/file.install ++++ b/core/modules/file/file.install +@@ -64,6 +64,7 @@ function file_schema() { + */ + function file_requirements($phase) { + $requirements = array(); ++ $t = get_t(); + + // Check the server's ability to indicate upload progress. + if ($phase == 'runtime') { +@@ -73,30 +74,30 @@ function file_requirements($phase) { + $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE; + $description = NULL; + if (!$apache) { +- $value = t('Not enabled'); +- $description = t('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php.'); ++ $value = $t('Not enabled'); ++ $description = $t('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php.'); + } + elseif ($fastcgi) { +- $value = t('Not enabled'); +- $description = t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php and not as FastCGI.'); ++ $value = $t('Not enabled'); ++ $description = $t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php and not as FastCGI.'); + } + elseif (!$implementation && extension_loaded('apc')) { +- $value = t('Not enabled'); +- $description = t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add apc.rfc1867 = 1 to your php.ini configuration. Alternatively, it is recommended to use PECL uploadprogress, which supports more than one simultaneous upload.', array('@url' => 'http://pecl.php.net/package/uploadprogress')); ++ $value = $t('Not enabled'); ++ $description = $t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add apc.rfc1867 = 1 to your php.ini configuration. Alternatively, it is recommended to use PECL uploadprogress, which supports more than one simultaneous upload.', array('@url' => 'http://pecl.php.net/package/uploadprogress')); + } + elseif (!$implementation) { +- $value = t('Not enabled'); +- $description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the PECL uploadprogress library (preferred) or to install APC.', array('@uploadprogress_url' => 'http://pecl.php.net/package/uploadprogress', '@apc_url' => 'http://php.net/apc')); ++ $value = $t('Not enabled'); ++ $description = $t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the PECL uploadprogress library (preferred) or to install APC.', array('@uploadprogress_url' => 'http://pecl.php.net/package/uploadprogress', '@apc_url' => 'http://php.net/apc')); + } + elseif ($implementation == 'apc') { +- $value = t('Enabled (APC RFC1867)', array('@url' => 'http://php.net/manual/apc.configuration.php#ini.apc.rfc1867')); +- $description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the PECL uploadprogress library if possible.', array('@url' => 'http://pecl.php.net/package/uploadprogress')); ++ $value = $t('Enabled (APC RFC1867)', array('@url' => 'http://php.net/manual/apc.configuration.php#ini.apc.rfc1867')); ++ $description = $t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the PECL uploadprogress library if possible.', array('@url' => 'http://pecl.php.net/package/uploadprogress')); + } + elseif ($implementation == 'uploadprogress') { +- $value = t('Enabled (PECL uploadprogress)', array('@url' => 'http://pecl.php.net/package/uploadprogress')); ++ $value = $t('Enabled (PECL uploadprogress)', array('@url' => 'http://pecl.php.net/package/uploadprogress')); + } + $requirements['file_progress'] = array( +- 'title' => t('Upload progress'), ++ 'title' => $t('Upload progress'), + 'value' => $value, + 'description' => $description, + ); +diff --git a/core/modules/file/file.module b/core/modules/file/file.module +index 03e10bf..9f83779 100644 +--- a/core/modules/file/file.module ++++ b/core/modules/file/file.module +@@ -81,7 +81,7 @@ function file_element_info() { + * + * @param array $fids + * (optional) An array of entity IDs. If omitted, all entities are loaded. +- * @param $reset ++ * @param bool $reset + * Whether to reset the internal file_load_multiple() cache. + * + * @return array +@@ -105,9 +105,9 @@ function file_load_multiple(array $fids = NULL, $reset = FALSE) { + /** + * Loads a single file entity from the database. + * +- * @param $fid ++ * @param int $fid + * A file ID. +- * @param $reset ++ * @param bool $reset + * Whether to reset the internal file_load_multiple() cache. + * + * @return \Drupal\file\FileInterface +@@ -144,10 +144,10 @@ function file_load($fid, $reset = FALSE) { + * + * @param \Drupal\file\FileInterface $source + * A file entity. +- * @param $destination ++ * @param string $destination + * A string containing the destination that $source should be copied to. + * This must be a stream wrapper URI. +- * @param $replace ++ * @param int $replace + * Replace behavior when the destination file already exists: + * - FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with + * the destination name exists then its database entry will be updated. If +@@ -156,7 +156,7 @@ function file_load($fid, $reset = FALSE) { + * unique. + * - FILE_EXISTS_ERROR - Do nothing and return FALSE. + * +- * @return ++ * @return Drupal/Entity/EntityInterface + * File object if the copy is successful, or FALSE in the event of an error. + * + * @see file_unmanaged_copy() +@@ -165,7 +165,11 @@ function file_load($fid, $reset = FALSE) { + function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { + if (!file_valid_uri($destination)) { + if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) { +- \Drupal::logger('file')->notice('File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination)); ++ \Drupal::logger('file')->notice('File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array( ++ '%file' => $source->getFileUri(), ++ '%realpath' => $realpath, ++ '%destination' => $destination) ++ ); + } + else { + \Drupal::logger('file')->notice('File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination)); +@@ -219,10 +223,10 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E + * + * @param \Drupal\file\FileInterface $source + * A file entity. +- * @param $destination ++ * @param string $destination + * A string containing the destination that $source should be moved to. + * This must be a stream wrapper URI. +- * @param $replace ++ * @param int $replace + * Replace behavior when the destination file already exists: + * - FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with + * the destination name exists then its database entry will be updated and +@@ -242,7 +246,11 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E + function file_move(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { + if (!file_valid_uri($destination)) { + if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) { +- \Drupal::logger('file')->notice('File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination)); ++ \Drupal::logger('file')->notice('File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array( ++ '%file' => $source->getFileUri(), ++ '%realpath' => $realpath, ++ '%destination' => $destination) ++ ); + } + else { + \Drupal::logger('file')->notice('File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination)); +@@ -295,7 +303,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E + * + * @param \Drupal\file\FileInterface $file + * A file entity. +- * @param $validators ++ * @param array $validators + * An optional, associative array of callback functions used to validate the + * file. The keys are function names and the values arrays of callback + * parameters which will be passed in after the file entity. The +@@ -303,12 +311,12 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E + * indicates that the file passed validation. The functions will be called in + * the order specified. + * +- * @return ++ * @return array + * An array containing validation error messages. + * + * @see hook_file_validate() + */ +-function file_validate(FileInterface $file, $validators = array()) { ++function file_validate(FileInterface $file, array $validators = array()) { + // Call the validation functions specified by this function's caller. + $errors = array(); + foreach ($validators as $function => $args) { +@@ -328,7 +336,7 @@ function file_validate(FileInterface $file, $validators = array()) { + * @param \Drupal\file\FileInterface $file + * A file entity. + * +- * @return ++ * @return array|string + * An array. If the file name is too long, it will contain an error message. + */ + function file_validate_name_length(FileInterface $file) { +@@ -348,10 +356,10 @@ function file_validate_name_length(FileInterface $file) { + * + * @param \Drupal\file\FileInterface $file + * A file entity. +- * @param $extensions ++ * @param string $extensions + * A string with a space separated list of allowed extensions. + * +- * @return ++ * @return array|string + * An array. If the file extension is not allowed, it will contain an error + * message. + * +@@ -372,14 +380,14 @@ function file_validate_extensions(FileInterface $file, $extensions) { + * + * @param \Drupal\file\FileInterface $file + * A file entity. +- * @param $file_limit ++ * @param int $file_limit + * An integer specifying the maximum file size in bytes. Zero indicates that + * no limit should be enforced. +- * @param $user_limit ++ * @param int $user_limit + * An integer specifying the maximum number of bytes the user is allowed. + * Zero indicates that no limit should be enforced. + * +- * @return ++ * @return array|string + * An array. If the file size exceeds limits, it will contain an error + * message. + * +@@ -407,7 +415,7 @@ function file_validate_size(FileInterface $file, $file_limit = 0, $user_limit = + * @param \Drupal\file\FileInterface $file + * A file entity. + * +- * @return ++ * @return array + * An array. If the file is not an image, it will contain an error message. + * + * @see hook_file_validate() +@@ -433,16 +441,16 @@ function file_validate_is_image(FileInterface $file) { + * + * @param \Drupal\file\FileInterface $file + * A file entity. This function may resize the file affecting its size. +- * @param $maximum_dimensions ++ * @param int $maximum_dimensions + * An optional string in the form WIDTHxHEIGHT e.g. '640x480' or '85x85'. If + * an image toolkit is installed the image will be resized down to these + * dimensions. A value of 0 indicates no restriction on size, so resizing + * will be attempted. +- * @param $minimum_dimensions ++ * @param int $minimum_dimensions + * An optional string in the form WIDTHxHEIGHT. This will check that the + * image meets a minimum size. A value of 0 indicates no restriction. + * +- * @return ++ * @return array + * An array. If the file is an image and did not meet the requirements, it + * will contain an error message. + * +@@ -486,13 +494,13 @@ function file_validate_image_resolution(FileInterface $file, $maximum_dimensions + /** + * Saves a file to the specified destination and creates a database entry. + * +- * @param $data ++ * @param string $data + * A string containing the contents of the file. +- * @param $destination ++ * @param string $destination + * A string containing the destination URI. This must be a stream wrapper URI. + * If no value is provided, a randomized name will be generated and the file + * will be saved using Drupal's default files scheme, usually "public://". +- * @param $replace ++ * @param int $replace + * Replace behavior when the destination file already exists: + * - FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with + * the destination name exists then its database entry will be updated. If +@@ -555,7 +563,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM + * @param \Drupal\file\FileInterface $file + * A file entity. + * +- * @return ++ * @return array + * An associative array of headers, as expected by + * \Symfony\Component\HttpFoundation\StreamedResponse. + */ +@@ -576,7 +584,12 @@ function file_theme() { + return array( + // From file.module. + 'file_link' => array( +- 'variables' => array('file' => NULL, 'icon_directory' => NULL, 'description' => NULL, 'attributes' => array()), ++ 'variables' => array( ++ 'file' => NULL, ++ 'icon_directory' => NULL, ++ 'description' => NULL, ++ 'attributes' => array(), ++ ), + 'template' => 'file-link', + ), + 'file_managed_file' => array( +@@ -596,7 +609,11 @@ function file_theme() { + 'file' => 'file.field.inc', + ), + 'file_upload_help' => array( +- 'variables' => array('description' => NULL, 'upload_validators' => NULL, 'cardinality' => NULL), ++ 'variables' => array( ++ 'description' => NULL, ++ 'upload_validators' => NULL, ++ 'cardinality' => NULL, ++ ), + 'template' => 'file-upload-help', + 'file' => 'file.field.inc', + ), +@@ -608,7 +625,7 @@ function file_theme() { + */ + function file_file_download($uri) { + // Get the file record based on the URI. If not in the database just return. +- /** @var \Drupal\file\FileInterface[] $files */ ++ /* @var \Drupal\file\FileInterface[] $files */ + $files = entity_load_multiple_by_properties('file', array('uri' => $uri)); + if (count($files)) { + foreach ($files as $item) { +@@ -646,7 +663,7 @@ function file_file_download($uri) { + } + + /** +- * Implements file_cron() ++ * Implements file_cron(). + */ + function file_cron() { + $age = \Drupal::config('system.file')->get('temporary_maximum_age'); +@@ -671,7 +688,10 @@ function file_cron() { + } + } + else { +- \Drupal::logger('file system')->info('Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->getFileUri(), '%modules' => implode(', ', array_keys($references)))); ++ \Drupal::logger('file system')->info('Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array( ++ '%path' => $file->getFileUri(), ++ '%modules' => implode(', ', array_keys($references)), ++ )); + } + } + } +@@ -684,12 +704,10 @@ function file_cron() { + * Temporary files are periodically cleaned. Use the 'file.usage' service to + * register the usage of the file which will automatically mark it as permanent. + * +- * @param $form_field_name ++ * @param string $form_field_name + * A string that is the associative array key of the upload form element in + * the form array. +- * @param \Drupal\Core\Form\FormStateInterface $form_state +- * The current state of the form. +- * @param $validators ++ * @param array $validators + * An optional, associative array of callback functions used to validate the + * file. See file_validate() for a full discussion of the array format. + * If no extension validator is provided it will default to a limited safe +@@ -698,20 +716,20 @@ function file_cron() { + * explicitly set the 'file_validate_extensions' validator to an empty array + * (Beware: this is not safe and should only be allowed for trusted users, if + * at all). +- * @param $destination ++ * @param string $destination + * A string containing the URI that the file should be copied to. This must + * be a stream wrapper URI. If this value is omitted, Drupal's temporary + * files scheme will be used ("temporary://"). +- * @param $delta ++ * @param int $delta + * Delta of the file to save or NULL to save all files. Defaults to NULL. +- * @param $replace ++ * @param int $replace + * Replace behavior when the destination file already exists: + * - FILE_EXISTS_REPLACE: Replace the existing file. + * - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is + * unique. + * - FILE_EXISTS_ERROR: Do nothing and return FALSE. + * +- * @return ++ * @return array + * Function returns array of files or a single file object if $delta + * != NULL. Each file object contains the file information if the + * upload succeeded or FALSE in the event of an error. Function +@@ -724,7 +742,7 @@ function file_cron() { + * - source: Path to the file before it is moved. + * - destination: Path to the file after it is moved (same as 'uri'). + */ +-function file_save_upload($form_field_name, $validators = array(), $destination = FALSE, $delta = NULL, $replace = FILE_EXISTS_RENAME) { ++function file_save_upload($form_field_name, array $validators = array(), $destination = FALSE, $delta = NULL, $replace = FILE_EXISTS_RENAME) { + $user = \Drupal::currentUser(); + static $upload_cache; + +@@ -775,7 +793,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' => $file_info->getFilename())), 'error'); + $files[$i] = FALSE; +@@ -801,8 +819,8 @@ function file_save_upload($form_field_name, $validators = array(), $destination + } + else { + // If 'file_validate_extensions' is set and the list is empty then the +- // caller wants to allow any extension. In this case we have to remove the +- // validator or else it will reject all extensions. ++ // caller wants to allow any extension. In this case we have to remove ++ // the validator or else it will reject all extensions. + unset($validators['file_validate_extensions']); + } + } +@@ -828,8 +846,8 @@ function file_save_upload($form_field_name, $validators = array(), $destination + $file->setMimeType('text/plain'); + // The destination filename will also later be used to create the URI. + $file->setFilename($file->getFilename() . '.txt'); +- // The .txt extension may not be in the allowed list of extensions. We have +- // to add it here or else the file upload will fail. ++ // The .txt extension may not be in the allowed list of extensions. We ++ // have to add it here or else the file upload will fail. + if (!empty($extensions)) { + $validators['file_validate_extensions'][0] .= ' txt'; + drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $file->getFilename()))); +@@ -855,8 +873,8 @@ function file_save_upload($form_field_name, $validators = array(), $destination + $destination .= '/'; + } + $file->destination = file_destination($destination . $file->getFilename(), $replace); +- // If file_destination() returns FALSE then $replace === FILE_EXISTS_ERROR and +- // there's an existing file so we need to bail. ++ // If file_destination() returns FALSE then $replace === FILE_EXISTS_ERROR ++ // and there's an existing file so we need to bail. + if ($file->destination === FALSE) { + drupal_set_message(t('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', array('%source' => $form_field_name, '%directory' => $destination)), 'error'); + $files[$i] = FALSE; +@@ -927,7 +945,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination + /** + * Determines the preferred upload progress implementation. + * +- * @return ++ * @return string + * A string indicating which upload progress system is available. Either "apc" + * or "uploadprogress". If neither are available, returns FALSE. + */ +@@ -949,7 +967,7 @@ function file_progress_implementation() { + } + + /** +- * Implements hook_ENTITY_TYPE_predelete() for file entities. ++ * Implements hook_ENTITY_TYPE_predelete(). + */ + function file_file_predelete(File $file) { + // TODO: Remove references to a file that is in-use. +@@ -974,7 +992,7 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr + $replacements = array(); + + if ($type == 'file' && !empty($data['file'])) { +- /** @var \Drupal\file\FileInterface $file */ ++ /* @var \Drupal\file\FileInterface $file */ + $file = $data['file']; + + foreach ($tokens as $name => $original) { +@@ -984,7 +1002,7 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr + $replacements[$original] = $file->id(); + break; + +- // Essential file data ++ // Essential file data. + case 'name': + $replacements[$original] = $sanitize ? String::checkPlain($file->getFilename()) : $file->getFilename(); + break; +@@ -1234,8 +1252,14 @@ function file_managed_file_process($element, FormStateInterface $form_state, $fo + $element['upload']['#attached']['js'] = array( + array( + 'type' => 'setting', +- 'data' => array('file' => array('elements' => array('#' . $element['#id'] => $extension_list))) +- ) ++ 'data' => array( ++ 'file' => array( ++ 'elements' => array( ++ '#' . $element['#id'] => $extension_list, ++ ), ++ ), ++ ), ++ ), + ); + } + +@@ -1398,8 +1422,8 @@ function file_managed_file_submit($form, FormStateInterface $form_state) { + + foreach ($remove_fids as $fid) { + // If it's a temporary file we can safely remove it immediately, otherwise +- // it's up to the implementing module to remove usages of files to have them +- // removed. ++ // it's up to the implementing module to remove usages of files to have ++ // them removed. + if ($element['#files'][$fid] && $element['#files'][$fid]->isTemporary()) { + $element['#files'][$fid]->delete(); + } +@@ -1427,16 +1451,16 @@ function file_managed_file_submit($form, FormStateInterface $form_state) { + /** + * Saves any files that have been uploaded into a managed_file element. + * +- * @param $element ++ * @param array $element + * The FAPI element whose values are being saved. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * +- * @return ++ * @return array + * An array of file entities for each file that was saved, keyed by its file + * ID, or FALSE if no files were saved. + */ +-function file_managed_file_save_upload($element, FormStateInterface $form_state) { ++function file_managed_file_save_upload(array $element, FormStateInterface $form_state) { + $upload_name = implode('_', $element['#parents']); + $file_upload = \Drupal::request()->files->get("files[$upload_name]", NULL, TRUE); + if (empty($file_upload)) { +@@ -1462,7 +1486,9 @@ function file_managed_file_save_upload($element, FormStateInterface $form_state) + + // Value callback expects FIDs to be keys. + $files = array_filter($files); +- $fids = array_map(function($file) { return $file->id(); }, $files); ++ $fids = array_map(function ($file) { ++ return $file->id(); ++ }, $files); + + return empty($files) ? array() : array_combine($fids, $files); + } +@@ -1479,7 +1505,7 @@ function file_managed_file_save_upload($element, FormStateInterface $form_state) + * An associative array containing: + * - element: A render element representing the file. + */ +-function template_preprocess_file_managed_file(&$variables) { ++function template_preprocess_file_managed_file(array &$variables) { + $element = $variables['element']; + + $variables['attributes'] = array(); +@@ -1540,7 +1566,7 @@ function file_managed_file_pre_render($element) { + * - description: A description to be displayed instead of the filename. + * - attributes: An associative array of attributes to be placed in the a tag. + */ +-function template_preprocess_file_link(&$variables) { ++function template_preprocess_file_link(array &$variables) { + $file = $variables['file']; + $options = array( + 'attributes' => $variables['attributes'], +@@ -1598,11 +1624,11 @@ function template_preprocess_file_link(&$variables) { + * + * @param \Drupal\file\FileInterface $file + * A file entity. +- * @param $icon_directory ++ * @param string $icon_directory + * (optional) A path to a directory of icons to be used for files. Defaults to + * the value of the "icon.directory" variable. + * +- * @return ++ * @return string + * A URL string to the icon, or FALSE if an appropriate icon cannot be found. + */ + function file_icon_url(FileInterface $file, $icon_directory = NULL) { +@@ -1617,11 +1643,11 @@ function file_icon_url(FileInterface $file, $icon_directory = NULL) { + * + * @param \Drupal\file\FileInterface $file + * A file entity. +- * @param $icon_directory ++ * @param string $icon_directory + * (optional) A path to a directory of icons to be used for files. Defaults to + * the value of the "icon.directory" variable. + * +- * @return ++ * @return string + * A string to the icon as a local path, or FALSE if an appropriate icon could + * not be found. + */ +@@ -1671,7 +1697,7 @@ function file_icon_path(FileInterface $file, $icon_directory = NULL) { + * @param \Drupal\file\FileInterface $file + * A file entity. + * +- * @return ++ * @return string + * The generic icon MIME package expected for this file. + */ + function file_icon_map(FileInterface $file) { +@@ -1797,21 +1823,21 @@ function file_icon_map(FileInterface $file) { + * @param \Drupal\file\FileInterface $file + * A file entity. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field +- * (optional) A field definition to be used for this check. If given, limits the +- * reference check to the given field. +- * @param $age ++ * (optional) A field definition to be used for this check. If given, limits ++ * the reference check to the given field. ++ * @param string $age + * (optional) A constant that specifies which references to count. Use + * EntityStorageInterface::FIELD_LOAD_REVISION to retrieve all + * references within all revisions or + * EntityStorageInterface::FIELD_LOAD_CURRENT to retrieve references + * only in the current revisions. +- * @param $field_type ++ * @param string $field_type + * (optional) The name of a field type. If given, limits the reference check + * to fields of the given type. If both $field and $field_type is given but + * $field is not the same type as $field_type, an empty array will be + * returned. + * +- * @return ++ * @return array + * A multidimensional array. The keys are field_name, entity_type, + * entity_id and the value is an entity referencing this file. + * +@@ -1908,6 +1934,7 @@ function file_permission() { + * + * @param int $choice + * integer Status code. ++ * + * @return string + * string Text-represented file status. + */ +diff --git a/core/modules/file/src/FileAccessControlHandler.php b/core/modules/file/src/FileAccessControlHandler.php +index ee62c22..83ae025 100644 +--- a/core/modules/file/src/FileAccessControlHandler.php ++++ b/core/modules/file/src/FileAccessControlHandler.php +@@ -21,11 +21,10 @@ class FileAccessControlHandler extends EntityAccessControlHandler { + * {@inheritdoc} + */ + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { +- + if ($operation == 'download') { + foreach ($this->getFileReferences($entity) as $field_name => $entity_map) { + foreach ($entity_map as $referencing_entity_type => $referencing_entities) { +- /** @var \Drupal\Core\Entity\EntityInterface $referencing_entity */ ++ /* @var \Drupal\Core\Entity\EntityInterface $referencing_entity */ + foreach ($referencing_entities as $referencing_entity) { + if ($referencing_entity->access('view', $account) && $referencing_entity->$field_name->access('view', $account)) { + return TRUE; diff --git a/core/modules/file/src/FileUsage/FileUsageInterface.php b/core/modules/file/src/FileUsage/FileUsageInterface.php index 63600b5..85faf0d 100644 --- a/core/modules/file/src/FileUsage/FileUsageInterface.php @@ -33,21 +719,330 @@ */ public function listUsage(FileInterface $file); } +diff --git a/core/modules/file/src/FileViewsData.php b/core/modules/file/src/FileViewsData.php +index 5a977a2..fd1d430 100644 +--- a/core/modules/file/src/FileViewsData.php ++++ b/core/modules/file/src/FileViewsData.php +@@ -25,7 +25,7 @@ public function getViewsData() { + $data['file_managed']['table']['base']['defaults']['field'] = 'filename'; + $data['file_managed']['table']['wizard_id'] = 'file_managed'; + +- $data['file_managed']['fid']['field']['id'] ='file'; ++ $data['file_managed']['fid']['field']['id'] = 'file'; + $data['file_managed']['fid']['argument'] = array( + 'id' => 'file_fid', + // The field to display in the summary. +@@ -55,7 +55,7 @@ public function getViewsData() { + 'field' => array( + 'id' => 'file_extension', + 'click sortable' => FALSE, +- ), ++ ), + ); + + $data['file_managed']['filesize']['field']['id'] = 'file_size'; +@@ -119,14 +119,20 @@ public function getViewsData() { + // relationships are type-restricted in the joins declared above, and + // file->entity relationships are type-restricted in the relationship + // declarations below. +- + // Describes relationships between files and nodes. + $data['file_usage']['file_to_node'] = array( + 'title' => t('Content'), + 'help' => t('Content that is associated with this file, usually because this file is in a field on the content.'), + // Only provide this field/relationship/etc., + // when the 'file_managed' base table is present. +- 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'id', + 'relationship' => array( + 'title' => t('Content'), +@@ -134,7 +140,12 @@ public function getViewsData() { + 'base' => 'node', + 'base field' => 'nid', + 'relationship field' => 'id', +- 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'node')), ++ 'extra' => array(array( ++ 'table' => 'file_usage', ++ 'field' => 'type', ++ 'operator' => '=', ++ 'value' => 'node', ++ )), + ), + ); + $data['file_usage']['node_to_file'] = array( +@@ -142,7 +153,13 @@ public function getViewsData() { + 'help' => t('A file that is associated with this node, usually because it is in a field on the node.'), + // Only provide this field/relationship/etc., + // when the 'node' base table is present. +- 'skip base' => array('file_managed', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'file_managed', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'fid', + 'relationship' => array( + 'title' => t('File'), +@@ -159,7 +176,14 @@ public function getViewsData() { + 'help' => t('A user that is associated with this file, usually because this file is in a field on the user.'), + // Only provide this field/relationship/etc., + // when the 'file_managed' base table is present. +- 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'id', + 'relationship' => array( + 'title' => t('User'), +@@ -167,7 +191,12 @@ public function getViewsData() { + 'base' => 'users', + 'base field' => 'uid', + 'relationship field' => 'id', +- 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'user')), ++ 'extra' => array(array( ++ 'table' => 'file_usage', ++ 'field' => 'type', ++ 'operator' => '=', ++ 'value' => 'user', ++ )), + ), + ); + $data['file_usage']['user_to_file'] = array( +@@ -175,7 +204,14 @@ public function getViewsData() { + 'help' => t('A file that is associated with this user, usually because it is in a field on the user.'), + // Only provide this field/relationship/etc., + // when the 'users' base table is present. +- 'skip base' => array('file_managed', 'node', 'node_field_revision', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'file_managed', ++ 'node', ++ 'node_field_revision', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'fid', + 'relationship' => array( + 'title' => t('File'), +@@ -192,7 +228,14 @@ public function getViewsData() { + 'help' => t('A comment that is associated with this file, usually because this file is in a field on the comment.'), + // Only provide this field/relationship/etc., + // when the 'file_managed' base table is present. +- 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'id', + 'relationship' => array( + 'title' => t('Comment'), +@@ -200,7 +243,12 @@ public function getViewsData() { + 'base' => 'comment', + 'base field' => 'cid', + 'relationship field' => 'id', +- 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'comment')), ++ 'extra' => array(array( ++ 'table' => 'file_usage', ++ 'field' => 'type', ++ 'operator' => '=', ++ 'value' => 'comment', ++ )), + ), + ); + $data['file_usage']['comment_to_file'] = array( +@@ -208,7 +256,14 @@ public function getViewsData() { + 'help' => t('A file that is associated with this comment, usually because it is in a field on the comment.'), + // Only provide this field/relationship/etc., + // when the 'comment' base table is present. +- 'skip base' => array('file_managed', 'node', 'node_field_revision', 'users', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'file_managed', ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'fid', + 'relationship' => array( + 'title' => t('File'), +@@ -225,7 +280,14 @@ public function getViewsData() { + 'help' => t('A taxonomy term that is associated with this file, usually because this file is in a field on the taxonomy term.'), + // Only provide this field/relationship/etc., + // when the 'file_managed' base table is present. +- 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'id', + 'relationship' => array( + 'title' => t('Taxonomy Term'), +@@ -233,7 +295,12 @@ public function getViewsData() { + 'base' => 'taxonomy_term_data', + 'base field' => 'tid', + 'relationship field' => 'id', +- 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_term')), ++ 'extra' => array(array( ++ 'table' => 'file_usage', ++ 'field' => 'type', ++ 'operator' => '=', ++ 'value' => 'taxonomy_term', ++ )), + ), + ); + $data['file_usage']['taxonomy_term_to_file'] = array( +@@ -241,7 +308,14 @@ public function getViewsData() { + 'help' => t('A file that is associated with this taxonomy term, usually because it is in a field on the taxonomy term.'), + // Only provide this field/relationship/etc., + // when the 'taxonomy_term_data' base table is present. +- 'skip base' => array('file_managed', 'node', 'node_field_revision', 'users', 'comment', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'file_managed', ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'fid', + 'relationship' => array( + 'title' => t('File'), +@@ -258,7 +332,14 @@ public function getViewsData() { + 'help' => t('A taxonomy vocabulary that is associated with this file, usually because this file is in a field on the taxonomy vocabulary.'), + // Only provide this field/relationship/etc., + // when the 'file_managed' base table is present. +- 'skip base' => array('node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data', 'taxonomy_vocabulary'), ++ 'skip base' => array( ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ 'taxonomy_vocabulary', ++ ), + 'real field' => 'id', + 'relationship' => array( + 'title' => t('Taxonomy Vocabulary'), +@@ -266,7 +347,12 @@ public function getViewsData() { + 'base' => 'taxonomy_vocabulary', + 'base field' => 'vid', + 'relationship field' => 'id', +- 'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_vocabulary')), ++ 'extra' => array(array( ++ 'table' => 'file_usage', ++ 'field' => 'type', ++ 'operator' => '=', ++ 'value' => 'taxonomy_vocabulary', ++ )), + ), + ); + $data['file_usage']['taxonomy_vocabulary_to_file'] = array( +@@ -274,7 +360,14 @@ public function getViewsData() { + 'help' => t('A file that is associated with this taxonomy vocabulary, usually because it is in a field on the taxonomy vocabulary.'), + // Only provide this field/relationship/etc., + // when the 'taxonomy_vocabulary' base table is present. +- 'skip base' => array('file_managed', 'node', 'node_field_revision', 'users', 'comment', 'taxonomy_term_data'), ++ 'skip base' => array( ++ 'file_managed', ++ 'node', ++ 'node_field_revision', ++ 'users', ++ 'comment', ++ 'taxonomy_term_data', ++ ), + 'real field' => 'fid', + 'relationship' => array( + 'title' => t('File'), +@@ -285,15 +378,15 @@ public function getViewsData() { + ), + ); + +- // Provide basic fields from the {file_usage} table to all of the base tables +- // we've declared joins to, because there is no 'skip base' property on these +- // fields. ++ // Provide basic fields from the {file_usage} table to all of the base ++ // tables we've declared joins to, because there is no 'skip base' property ++ // on these fields. + $data['file_usage']['module'] = array( + 'title' => t('Module'), + 'help' => t('The module managing this file relationship.'), + 'field' => array( + 'id' => 'standard', +- ), ++ ), + 'filter' => array( + 'id' => 'string', + ), +@@ -309,7 +402,7 @@ public function getViewsData() { + 'help' => t('The type of entity that is related to the file.'), + 'field' => array( + 'id' => 'standard', +- ), ++ ), + 'filter' => array( + 'id' => 'string', + ), +@@ -341,7 +434,7 @@ public function getViewsData() { + 'help' => t('The number of times the file is used by this entity.'), + 'field' => array( + 'id' => 'numeric', +- ), ++ ), + 'filter' => array( + 'id' => 'numeric', + ), +diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php b/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php +index f8ee03c..56ded38 100644 +--- a/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php ++++ b/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php +@@ -18,7 +18,8 @@ class FileFieldItemList extends EntityReferenceFieldItemList { + /** + * {@inheritdoc} + */ +- public function defaultValuesForm(array &$form, FormStateInterface $form_state) { } ++ public function defaultValuesForm(array &$form, FormStateInterface $form_state) { ++ } + + /** + * {@inheritdoc} diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php -index 9f80a6f..6b8cceb 100644 +index c84da26..2187bcb 100644 --- a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php -@@ -19,7 +19,8 @@ +@@ -21,7 +21,7 @@ * @FieldType( * id = "file", * label = @Translation("File"), - * description = @Translation("This field stores the ID of a file as an integer value."), -+ * description = @Translation("This field stores the ID of a file -+ * as an integer value."), ++ * description = @Translation("This field stores the file ID as an integer."), * default_widget = "file_generic", * default_formatter = "file_default", * list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList" -@@ -200,11 +201,11 @@ public function instanceSettingsForm(array $form, FormStateInterface $form_state +@@ -202,11 +202,11 @@ public function instanceSettingsForm(array $form, FormStateInterface $form_state } /** @@ -62,25 +1057,7 @@ * * This function is assigned as an #element_validate callback in * instanceSettingsForm(). -@@ -223,7 +224,8 @@ public static function validateDirectory($element, FormStateInterface $form_stat - * - * This doubles as a convenience clean-up function and a validation routine. - * Commas are allowed by the end-user, but ultimately the value will be stored -- * as a space-separated list for compatibility with file_validate_extensions(). -+ * as a space-separated list for compatibility with -+ * file_validate_extensions(). - */ - public static function validateExtensions($element, FormStateInterface $form_state) { - if (!empty($element['#value'])) { -@@ -250,17 +252,17 @@ public static function validateExtensions($element, FormStateInterface $form_sta - */ - public static function validateMaxFilesize($element, FormStateInterface $form_state) { - if (!empty($element['#value']) && !is_numeric(Bytes::toInt($element['#value']))) { -- form_error($element, $form_state, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); -+ form_error($element, $form_state, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => $element['title']))); - } - } - +@@ -259,15 +259,15 @@ public static function validateMaxFilesize($element, FormStateInterface $form_st /** * Determines the URI for a file field instance. * @@ -93,7 +1070,13 @@ * A file directory URI with tokens replaced. * * @see token_replace() -@@ -278,7 +280,7 @@ public function getUploadLocation($data = array()) { + */ +- public function getUploadLocation($data = array()) { ++ public function getUploadLocation(array $data = array()) { + $settings = $this->getSettings(); + $destination = trim($settings['file_directory'], '/'); + +@@ -280,7 +280,7 @@ public function getUploadLocation($data = array()) { /** * Retrieves the upload validators for a file field. * @@ -102,8 +1085,17 @@ * An array suitable for passing to file_save_upload() or the file field * element's '#upload_validators' property. */ +@@ -318,7 +318,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin + $file = file_save_data($data, $destination, FILE_EXISTS_ERROR); + $values = array( + 'target_id' => $file->id(), +- 'display' => (int)$settings['display_default'], ++ 'display' => (int) $settings['display_default'], + 'description' => $random->sentences(10), + ); + return $values; diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php -index fa5c28e..ec7090a 100644 +index f9becf4..3c8954d 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -302,8 +302,9 @@ public static function value($element, $input = FALSE, FormStateInterface $form_ @@ -118,7 +1110,21 @@ * * This validator is used only when cardinality not set to 1 or unlimited. */ -@@ -405,7 +406,9 @@ public static function process($element, FormStateInterface $form_state, $form) +@@ -326,7 +327,12 @@ public static function validateMultipleCount($element, FormStateInterface $form_ + $file = file_load($fid); + $removed_names[] = $file->getFilename(); + } +- $args = array('%field' => $field_storage->getFieldName(), '@max' => $field_storage->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names)); ++ $args = array( ++ '%field' => $field_storage->getFieldName(), ++ '@max' => $field_storage->getCardinality(), ++ '@count' => $keep, ++ '%list' => implode(', ', $removed_names), ++ ); + $message = t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args); + drupal_set_message($message, 'warning'); + $values['fids'] = array_slice($values['fids'], 0, $keep); +@@ -405,7 +411,9 @@ public static function process($element, FormStateInterface $form_state, $form) // not just the individual item, to be valid. foreach (array('upload_button', 'remove_button') as $key) { $element[$key]['#submit'][] = array(get_called_class(), 'submit'); @@ -129,10 +1135,28 @@ } return $element; +@@ -465,7 +473,7 @@ public static function processMultiple($element, FormStateInterface $form_state, + * A description of the file suitable for use in the administrative + * interface. + */ +- protected static function getDescriptionFromElement($element) { ++ protected static function getDescriptionFromElement(array $element) { + // Use the actual file description, if it's available. + if (!empty($element['#default_value']['description'])) { + return $element['#default_value']['description']; diff --git a/core/modules/file/src/Plugin/views/argument/Fid.php b/core/modules/file/src/Plugin/views/argument/Fid.php -index a296a0c..cd2c9b7 100644 +index a296a0c..4132657 100644 --- a/core/modules/file/src/Plugin/views/argument/Fid.php +++ b/core/modules/file/src/Plugin/views/argument/Fid.php +@@ -24,7 +24,7 @@ + class Fid extends Numeric implements ContainerFactoryPluginInterface { + + /** +- * The entity manager service ++ * The entity manager service. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ @@ -48,7 +48,7 @@ class Fid extends Numeric implements ContainerFactoryPluginInterface { * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -142,35 +1166,93 @@ * The entity query factory. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, QueryFactory $entity_query) { +diff --git a/core/modules/file/src/Plugin/views/field/File.php b/core/modules/file/src/Plugin/views/field/File.php +index 135ff7f..8d2ef02 100644 +--- a/core/modules/file/src/Plugin/views/field/File.php ++++ b/core/modules/file/src/Plugin/views/field/File.php +@@ -33,6 +33,9 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o + } + } + ++ /** ++ * {@inheritdoc} ++ */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['link_to_file'] = array('default' => FALSE, 'bool' => TRUE); +@@ -40,7 +43,7 @@ protected function defineOptions() { + } + + /** +- * Provide link to file option ++ * Provide link to file option. + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['link_to_file'] = array( diff --git a/core/modules/file/src/Plugin/views/field/FileMime.php b/core/modules/file/src/Plugin/views/field/FileMime.php -index 5576e34..4603751 100644 +index 5576e34..fe2629d 100644 --- a/core/modules/file/src/Plugin/views/field/FileMime.php +++ b/core/modules/file/src/Plugin/views/field/FileMime.php -@@ -11,7 +11,8 @@ +@@ -11,7 +11,7 @@ use Drupal\views\ResultRow; /** - * Field handler to add rendering MIME type images as an option on the filemime field. -+ * Field handler to add rendering MIME type images as an option -+ * on the filemime field. ++ * Field handler to add rendering MIME type images as option on filemime field. * * @ingroup views_field_handlers * +@@ -19,12 +19,18 @@ + */ + class FileMime extends File { + ++ /** ++ * {@inheritdoc} ++ */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['filemime_image'] = array('default' => FALSE, 'bool' => TRUE); + return $options; + } + ++ /** ++ * {@inheritdoc} ++ */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['filemime_image'] = array( + '#title' => t('Display an icon representing the file type, instead of the MIME text (such as "image/jpeg")'), diff --git a/core/modules/file/src/Plugin/views/field/Uri.php b/core/modules/file/src/Plugin/views/field/Uri.php -index 2d2c481..4dab77b 100644 +index 2d2c481..c3208bf 100644 --- a/core/modules/file/src/Plugin/views/field/Uri.php +++ b/core/modules/file/src/Plugin/views/field/Uri.php -@@ -11,7 +11,9 @@ +@@ -11,18 +11,26 @@ use Drupal\views\ResultRow; /** - * Field handler to add rendering file paths as file URLs instead of as internal file URIs. + * Field handler to add rendering file paths as file URLs. + * -+ * instead of as internal file URIs. ++ * Instead of as internal file URIs. * * @ViewsField("file_uri") */ + class Uri extends File { + ++ /** ++ * {@inheritdoc} ++ */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['file_download_path'] = array('default' => FALSE, 'bool' => TRUE); + return $options; + } + ++ /** ++ * {@inheritdoc} ++ */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['file_download_path'] = array( + '#title' => t('Display download path instead of file storage URI'), diff --git a/core/modules/file/src/Plugin/views/wizard/File.php b/core/modules/file/src/Plugin/views/wizard/File.php index 94529a0..d3d4ff0 100644 --- a/core/modules/file/src/Plugin/views/wizard/File.php @@ -236,7 +1318,7 @@ $source = $this->createFile(); $target = $this->createFile(NULL, $contents); diff --git a/core/modules/file/src/Tests/DeleteTest.php b/core/modules/file/src/Tests/DeleteTest.php -index f39239f..f9aa34e 100644 +index f39239f..b8b035f 100644 --- a/core/modules/file/src/Tests/DeleteTest.php +++ b/core/modules/file/src/Tests/DeleteTest.php @@ -16,7 +16,7 @@ class DeleteTest extends FileManagedUnitTestBase { @@ -257,20 +1339,32 @@ $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); $file_usage->add($file, 'testing', 'test', 1); +@@ -66,7 +66,7 @@ function testInUse() { + ->execute(); + \Drupal::service('cron')->run(); + +- // file_cron() loads ++ // file_cron() loads. + $this->assertFileHooksCalled(array('delete')); + $this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); + $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); diff --git a/core/modules/file/src/Tests/DownloadTest.php b/core/modules/file/src/Tests/DownloadTest.php -index 92ba740..76dacd2 100644 +index 92ba740..386b332 100644 --- a/core/modules/file/src/Tests/DownloadTest.php +++ b/core/modules/file/src/Tests/DownloadTest.php -@@ -15,7 +15,7 @@ +@@ -15,7 +15,10 @@ * @group file */ class DownloadTest extends FileManagedTestBase { - protected function setUp() { ++ /** ++ * {@inheritdoc} ++ */ + public function setUp() { parent::setUp(); // Clear out any hook calls. file_test_reset(); -@@ -24,12 +24,12 @@ protected function setUp() { +@@ -24,12 +27,12 @@ protected function setUp() { /** * Test the public file transfer system. */ @@ -286,7 +1380,15 @@ $filename = $GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename()); $this->assertEqual($filename, $url, 'Correctly generated a URL for a created file.'); $this->drupalHead($url); -@@ -99,14 +99,17 @@ protected function doPrivateFileTransferTest() { +@@ -69,7 +72,6 @@ public function testPrivateFileTransferWithPageCache() { + */ + protected function doPrivateFileTransferTest() { + // Set file downloads to private so handler functions get called. +- + // Create a file. + $contents = $this->randomMachineName(8); + $file = $this->createFile(NULL, $contents, 'private'); +@@ -99,14 +101,17 @@ protected function doPrivateFileTransferTest() { /** * Test file_create_url(). */ @@ -308,24 +1410,29 @@ $basename_encoded = '%20-._%21%24%27%22%28%29%2A%40%5B%5D%3F%26%2B%25%23%2C%3B%3D%3A__' . '%2523%2525%2526%252B%252F%253F' . '%C3%A9%C3%B8%C3%AF%D0%B2%CE%B2%E4%B8%AD%E5%9C%8B%E6%9B%B8%DB%9E'; -@@ -135,13 +138,13 @@ function testFileCreateUrl() { +@@ -135,14 +140,14 @@ function testFileCreateUrl() { * the URL generated by file_create_url() for the specified file equals the * specified URL; fetch the URL and then compare the contents to the file. * - * @param $scheme -+ * @param string $scheme - * A scheme, e.g. "public" +- * A scheme, e.g. "public" - * @param $directory -+ * @param string $directory - * A directory, possibly "" +- * A directory, possibly "" - * @param $filename -+ * @param string $filename - * A filename +- * A filename - * @param $expected_url +- * The expected URL ++ * @param string $scheme ++ * A scheme, e.g. "public". ++ * @param string $directory ++ * A directory, possibly "". ++ * @param string $filename ++ * A filename. + * @param string $expected_url - * The expected URL ++ * The expected URL. */ private function checkUrl($scheme, $directory, $filename, $expected_url) { + // Convert $filename to a valid filename, i.e. strip characters not diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index 6a1798d..d65e289 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -437,10 +1544,18 @@ $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php -index fb9552a..8ef1222 100644 +index fb9552a..5ba7f70 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php -@@ -18,25 +18,36 @@ +@@ -7,6 +7,7 @@ + + namespace Drupal\file\Tests; + ++use Drupal\Core\Entity\EntityInterface; + use Drupal\field\Entity\FieldStorageConfig; + use Drupal\field\Entity\FieldInstanceConfig; + use Drupal\file\FileInterface; +@@ -18,25 +19,39 @@ abstract class FileFieldTestBase extends WebTestBase { /** @@ -457,6 +1572,9 @@ - protected $admin_user; + protected $adminUser; ++ /** ++ * {@inheritdoc} ++ */ protected function setUp() { parent::setUp(); - $this->admin_user = $this->drupalCreateUser(array('access content', 'access administration pages', 'administer site configuration', 'administer users', 'administer permissions', 'administer content types', 'administer node fields', 'administer node display', 'administer nodes', 'bypass node access')); @@ -485,7 +1603,7 @@ // Get a file to upload. $file = current($this->drupalGetTestFiles($type_name, $size)); -@@ -49,27 +60,28 @@ function getTestFile($type_name, $size = NULL) { +@@ -49,27 +64,29 @@ function getTestFile($type_name, $size = NULL) { /** * Retrieves the fid of the last inserted file. */ @@ -506,8 +1624,8 @@ - * @param $bundle + * @param string $bundle * The bundle that this field will be added to. -+ * @param array $field_settings - * @param $storage_settings +- * @param $storage_settings ++ * @param array $storage_settings * A list of field storage settings that will be added to the defaults. - * @param $instance_settings + * @param array $instance_settings @@ -515,13 +1633,15 @@ - * @param $widget_settings + * @param array $widget_settings * A list of widget settings that will be added to the widget defaults. ++ * ++ * @return EntityInterface */ - function createFileField($name, $entity_type, $bundle, $storage_settings = array(), $instance_settings = array(), $widget_settings = array()) { -+ public function createFileField($name, $entity_type, $bundle, $storage_settings = array(), $instance_settings = array(), $widget_settings = array()) { ++ public function createFileField($name, $entity_type, $bundle, array $storage_settings = array(), array $instance_settings = array(), array $widget_settings = array()) { $field_storage = entity_create('field_storage_config', array( 'entity_type' => $entity_type, 'name' => $name, -@@ -86,20 +98,18 @@ function createFileField($name, $entity_type, $bundle, $storage_settings = array +@@ -86,20 +103,18 @@ function createFileField($name, $entity_type, $bundle, $storage_settings = array /** * Attaches a file field to an entity. * @@ -544,11 +1664,11 @@ * A list of widget settings that will be added to the widget defaults. */ - function attachFileField($name, $entity_type, $bundle, $instance_settings = array(), $widget_settings = array()) { -+ public function attachFileField($name, $entity_type, $bundle, $instance_settings = array(), $widget_settings = array()) { ++ public function attachFileField($name, $entity_type, $bundle, array $instance_settings = array(), array $widget_settings = array()) { $instance = array( 'field_name' => $name, 'label' => $name, -@@ -122,7 +132,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra +@@ -122,7 +137,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra /** * Updates an existing file field with new settings. */ @@ -557,7 +1677,7 @@ $instance = FieldInstanceConfig::loadByName('node', $type_name, $name); $instance->settings = array_merge($instance->settings, $instance_settings); $instance->save(); -@@ -137,7 +147,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge +@@ -137,7 +152,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge /** * Uploads a file to a node. */ @@ -566,7 +1686,7 @@ $edit = array( 'title[0][value]' => $this->randomMachineName(), 'revision' => (string) (int) $new_revision, -@@ -175,7 +185,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, +@@ -175,7 +190,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, * * Note that if replacing a file, it must first be removed then added again. */ @@ -575,7 +1695,7 @@ $edit = array( 'revision' => (string) (int) $new_revision, ); -@@ -187,7 +197,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { +@@ -187,7 +202,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { /** * Replaces a file within a node. */ @@ -584,7 +1704,7 @@ $edit = array( 'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()), 'revision' => (string) (int) $new_revision, -@@ -200,7 +210,7 @@ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { +@@ -200,7 +215,7 @@ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { /** * Asserts that a file exists physically on disk. */ @@ -593,7 +1713,7 @@ $message = isset($message) ? $message : format_string('File %file exists on the disk.', array('%file' => $file->getFileUri())); $this->assertTrue(is_file($file->getFileUri()), $message); } -@@ -208,7 +218,7 @@ function assertFileExists($file, $message = NULL) { +@@ -208,7 +223,7 @@ function assertFileExists($file, $message = NULL) { /** * Asserts that a file exists in the database. */ @@ -602,7 +1722,7 @@ $this->container->get('entity.manager')->getStorage('file')->resetCache(); $db_file = file_load($file->id()); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); -@@ -218,7 +228,7 @@ function assertFileEntryExists($file, $message = NULL) { +@@ -218,7 +233,7 @@ function assertFileEntryExists($file, $message = NULL) { /** * Asserts that a file does not exist on disk. */ @@ -611,7 +1731,7 @@ $message = isset($message) ? $message : format_string('File %file exists on the disk.', array('%file' => $file->getFileUri())); $this->assertFalse(is_file($file->getFileUri()), $message); } -@@ -226,7 +236,7 @@ function assertFileNotExists($file, $message = NULL) { +@@ -226,7 +241,7 @@ function assertFileNotExists($file, $message = NULL) { /** * Asserts that a file does not exist in the database. */ @@ -620,7 +1740,7 @@ $this->container->get('entity.manager')->getStorage('file')->resetCache(); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); $this->assertFalse(file_load($file->id()), $message); -@@ -235,7 +245,7 @@ function assertFileEntryNotExists($file, $message) { +@@ -235,7 +250,7 @@ function assertFileEntryNotExists($file, $message) { /** * Asserts that a file's status is set to permanent in the database. */ @@ -691,10 +1811,23 @@ $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php -index 9ae0940..9130ce9 100644 +index 9ae0940..9b76226 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php -@@ -28,7 +28,7 @@ class FileFieldWidgetTest extends FileFieldTestBase { +@@ -11,8 +11,10 @@ + use Drupal\field\Entity\FieldInstanceConfig; + + /** +- * Tests the file field widget, single and multi-valued, with and without AJAX, +- * with public and private files. ++ * Tests the file field widget. ++ * ++ * All options viz. single and multi-valued, with and without AJAX, ++ * with public and private files + * + * @group file + */ +@@ -28,7 +30,7 @@ class FileFieldWidgetTest extends FileFieldTestBase { /** * Tests upload and remove buttons for a single-valued File field. */ @@ -703,7 +1836,7 @@ $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); -@@ -59,6 +59,7 @@ function testSingleValuedWidget() { +@@ -59,6 +61,7 @@ function testSingleValuedWidget() { case 'nojs': $this->drupalPostForm(NULL, array(), t('Remove')); break; @@ -711,7 +1844,7 @@ case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Remove') . '"]'); $this->drupalPostAjaxForm(NULL, array(), array((string) $button[0]['name'] => (string) $button[0]['value'])); -@@ -82,7 +83,7 @@ function testSingleValuedWidget() { +@@ -82,7 +85,7 @@ function testSingleValuedWidget() { /** * Tests upload and remove buttons for multiple multi-valued File fields. */ @@ -720,7 +1853,7 @@ $type_name = 'article'; // Use explicit names instead of random names for those fields, because of a // bug in drupalPostForm() with multiple file uploads in one form, where the -@@ -103,15 +104,14 @@ function testMultiValuedWidget() { +@@ -103,15 +106,14 @@ function testMultiValuedWidget() { // until after the 3rd file, and after that, isn't displayed. Because // SimpleTest triggers the last button with a given name, so upload to the // second field first. @@ -740,7 +1873,7 @@ $this->drupalPostForm(NULL, $edit, t('Upload')); } } -@@ -122,13 +122,13 @@ function testMultiValuedWidget() { +@@ -122,13 +124,13 @@ function testMultiValuedWidget() { foreach (array($field_name, $field_name2) as $current_field_name) { // How many uploaded files for the current field are remaining. $remaining = 3; @@ -759,7 +1892,7 @@ // Ensure we have the expected number of Remove buttons, and that they // are numbered sequentially. $buttons = $this->xpath('//input[@type="submit" and @value="Remove"]'); -@@ -140,20 +140,21 @@ function testMultiValuedWidget() { +@@ -140,20 +142,21 @@ function testMultiValuedWidget() { $check_field_name = $field_name; } @@ -789,7 +1922,7 @@ foreach ($buttons as $button) { if ($button['name'] != $button_name) { $button['value'] = 'DUMMY'; -@@ -161,17 +162,18 @@ function testMultiValuedWidget() { +@@ -161,17 +164,18 @@ function testMultiValuedWidget() { } $this->drupalPostForm(NULL, array(), t('Remove')); break; @@ -812,7 +1945,7 @@ $upload_button_name = $current_field_name . '_' . $remaining . '_upload_button'; $buttons = $this->xpath('//input[@type="submit" and @value="Upload" and @name=:name]', array(':name' => $upload_button_name)); $this->assertTrue(is_array($buttons) && count($buttons) == 1, format_string('The upload button is displayed with the correct name (JSMode=%type).', array('%type' => $type))); -@@ -199,9 +201,9 @@ function testMultiValuedWidget() { +@@ -199,9 +203,9 @@ function testMultiValuedWidget() { /** * Tests a file field with a "Private files" upload destination setting. */ @@ -824,7 +1957,7 @@ $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); -@@ -236,11 +238,11 @@ function testPrivateFileSetting() { +@@ -236,11 +240,11 @@ function testPrivateFileSetting() { /** * Tests that download restrictions on private files work on comments. */ @@ -838,7 +1971,7 @@ user_role_grant_permissions($roles[1], array('administer comment fields', 'administer comments')); // Revoke access comments permission from anon user, grant post to -@@ -300,7 +302,7 @@ function testPrivateFileComment() { +@@ -300,7 +304,7 @@ function testPrivateFileComment() { $this->assertResponse(403, 'Confirmed that access is denied for the file without the needed permission.'); // Unpublishes node. @@ -847,7 +1980,7 @@ $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish')); // Ensures normal user can no longer download the file. -@@ -312,7 +314,7 @@ function testPrivateFileComment() { +@@ -312,7 +316,7 @@ function testPrivateFileComment() { /** * Tests validation with the Upload button. */ @@ -856,7 +1989,15 @@ $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); -@@ -341,16 +343,19 @@ function testWidgetValidation() { +@@ -333,6 +337,7 @@ function testWidgetValidation() { + case 'nojs': + $this->drupalPostForm(NULL, $edit, t('Upload')); + break; ++ + case 'js': + $button = $this->xpath('//input[@type="submit" and @value="' . t('Upload') . '"]'); + $this->drupalPostAjaxForm(NULL, $edit, array((string) $button[0]['name'] => (string) $button[0]['value'])); +@@ -341,16 +346,19 @@ function testWidgetValidation() { $error_message = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => 'txt')); $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', array('%type' => $type))); @@ -878,10 +2019,20 @@ $this->assertNoRaw($error_message, t('Validation error removed when file with correct extension uploaded (JSMode=%type).', array('%type' => $type))); } diff --git a/core/modules/file/src/Tests/FileItemTest.php b/core/modules/file/src/Tests/FileItemTest.php -index 82a2ceb..06bf822 100644 +index 0c55585..e4d938b 100644 --- a/core/modules/file/src/Tests/FileItemTest.php +++ b/core/modules/file/src/Tests/FileItemTest.php -@@ -61,7 +61,7 @@ protected function setUp() { +@@ -33,6 +33,9 @@ class FileItemTest extends FieldUnitTestBase { + */ + protected $file; + ++ /** ++ * {@inheritdoc} ++ */ + protected function setUp() { + parent::setUp(); + +@@ -61,7 +64,7 @@ protected function setUp() { * Tests using entity fields of the file field type. */ public function testFileItem() { @@ -891,10 +2042,19 @@ $entity->file_test->target_id = $this->file->id(); $entity->file_test->display = 1; diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php -index 216bb5f..b83bc14 100644 +index 216bb5f..681dc96 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php -@@ -32,8 +32,9 @@ protected function setUp() { +@@ -17,7 +17,7 @@ class FileListingTest extends FileFieldTestBase { + /** + * Modules to enable. + * +- * @var array ++ * @var array $modules + */ + public static $modules = array('views', 'file', 'image'); + +@@ -32,12 +32,13 @@ protected function setUp() { /** * Calculates total count of usages for a file. * @@ -905,6 +2065,11 @@ * @return int * Total usage count. */ +- protected function sumUsages($usage) { ++ protected function sumUsages(array $usage) { + $count = 0; + foreach ($usage as $module) { + foreach ($module as $entity_type) { @@ -53,7 +54,7 @@ protected function sumUsages($usage) { /** * Tests file overview with different user permissions. @@ -937,14 +2102,27 @@ $this->drupalGet('file/test'); $this->assertFieldByXpath('//input[@name="files[nested_file]" and @size="13"]', NULL, 'The custom #size attribute is passed to the child upload element.'); diff --git a/core/modules/file/src/Tests/FileManagedTestBase.php b/core/modules/file/src/Tests/FileManagedTestBase.php -index 3147f73..446fb9e 100644 +index 3147f73..263b200 100644 --- a/core/modules/file/src/Tests/FileManagedTestBase.php +++ b/core/modules/file/src/Tests/FileManagedTestBase.php -@@ -23,21 +23,22 @@ +@@ -11,8 +11,7 @@ + use Drupal\simpletest\WebTestBase; + + /** +- * Base class for file tests that use the file_test module to test uploads and +- * hooks. ++ * Base class for file tests that use the file_test module to test uploads and hooks. + */ + abstract class FileManagedTestBase extends WebTestBase { + +@@ -23,21 +22,25 @@ */ public static $modules = array('file_test', 'file'); - protected function setUp() { ++ /** ++ * {@inheritdoc} ++ */ + public function setUp() { parent::setUp(); // Clear out any hook calls. @@ -957,18 +2135,18 @@ + * Assert that all of the specified hook_file_* hooks were called once. * - * @param $expected -+ * other values result in failure. ++ * Other values result in failure. + * + * @param array $expected * Array with string containing with the hook name, e.g. 'load', 'save', * 'insert', etc. */ - function assertFileHooksCalled($expected) { -+ public function assertFileHooksCalled($expected) { ++ public function assertFileHooksCalled(array $expected) { \Drupal::state()->resetCache(); // Determine which hooks were called. -@@ -46,7 +47,11 @@ function assertFileHooksCalled($expected) { +@@ -46,7 +49,11 @@ function assertFileHooksCalled($expected) { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { @@ -981,7 +2159,7 @@ } else { $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', array('%expected' => empty($expected) ? '(none)' : implode(', ', $expected)))); -@@ -65,14 +70,14 @@ function assertFileHooksCalled($expected) { +@@ -65,14 +72,14 @@ function assertFileHooksCalled($expected) { /** * Assert that a hook_file_* hook was called a certain number of times. * @@ -1000,7 +2178,7 @@ $actual_count = count(file_test_get_calls($hook)); if (!isset($message)) { -@@ -83,7 +88,12 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { +@@ -83,7 +90,12 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count)); } else { @@ -1014,7 +2192,7 @@ } } $this->assertEqual($actual_count, $expected_count, $message); -@@ -97,7 +107,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { +@@ -97,7 +109,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { * @param \Drupal\file\FileInterface $after * File object to compare. */ @@ -1023,7 +2201,7 @@ $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged'); $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged'); $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged'); -@@ -115,7 +125,7 @@ function assertFileUnchanged(FileInterface $before, FileInterface $after) { +@@ -115,7 +127,7 @@ function assertFileUnchanged(FileInterface $before, FileInterface $after) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ @@ -1032,7 +2210,7 @@ $this->assertNotEqual($file1->id(), $file2->id(), t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->id(), '%file2' => $file2->id())), 'Different file'); $this->assertNotEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Different file'); } -@@ -128,28 +138,30 @@ function assertDifferentFile(FileInterface $file1, FileInterface $file2) { +@@ -128,28 +140,28 @@ function assertDifferentFile(FileInterface $file1, FileInterface $file2) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ @@ -1045,9 +2223,7 @@ /** - * Create a file and save it to the files table and assert that it occurs - * correctly. -+ * Create a file and save it to the files table and assert. -+ * -+ * that it occurs correctly. ++ * Create a file and save it to the files table and assert that it occurs correctly. * - * @param $filepath + * @param string $filepath @@ -1082,30 +2258,32 @@ // Prefix with non-latin characters to ensure that all file-related // tests work with international filenames. diff --git a/core/modules/file/src/Tests/FileManagedUnitTestBase.php b/core/modules/file/src/Tests/FileManagedUnitTestBase.php -index 051601a..2c240f9 100644 +index 051601a..7104745 100644 --- a/core/modules/file/src/Tests/FileManagedUnitTestBase.php +++ b/core/modules/file/src/Tests/FileManagedUnitTestBase.php -@@ -11,8 +11,8 @@ +@@ -11,8 +11,7 @@ use Drupal\simpletest\DrupalUnitTestBase; /** - * Base class for file unit tests that use the file_test module to test uploads and - * hooks. -+ * Base class for file unit tests that use the file_test module to test uploads -+ * and hooks. ++ * Base class for file tests using file_test module to test uploads and hooks. */ abstract class FileManagedUnitTestBase extends DrupalUnitTestBase { -@@ -23,7 +23,7 @@ +@@ -23,7 +22,10 @@ */ public static $modules = array('file_test', 'file', 'system', 'field', 'user'); - protected function setUp() { ++ /** ++ * {@inheritdoc} ++ */ + public function setUp() { parent::setUp(); // Clear out any hook calls. file_test_reset(); -@@ -42,14 +42,15 @@ protected function setUp() { +@@ -42,14 +44,15 @@ protected function setUp() { } /** @@ -1114,18 +2292,18 @@ + * Assert that all of the specified hook_file_* hooks were called once. * - * @param $expected -+ * other values result in failure. ++ * Other values result in failure. + * + * @param array $expected * Array with string containing with the hook name, e.g. 'load', 'save', * 'insert', etc. */ - function assertFileHooksCalled($expected) { -+ public function assertFileHooksCalled($expected) { ++ public function assertFileHooksCalled(array $expected) { \Drupal::state()->resetCache(); // Determine which hooks were called. -@@ -58,7 +59,11 @@ function assertFileHooksCalled($expected) { +@@ -58,7 +61,11 @@ function assertFileHooksCalled($expected) { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { @@ -1138,7 +2316,7 @@ } else { $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', array('%expected' => empty($expected) ? '(none)' : implode(', ', $expected)))); -@@ -77,14 +82,14 @@ function assertFileHooksCalled($expected) { +@@ -77,14 +84,14 @@ function assertFileHooksCalled($expected) { /** * Assert that a hook_file_* hook was called a certain number of times. * @@ -1157,7 +2335,7 @@ $actual_count = count(file_test_get_calls($hook)); if (!isset($message)) { -@@ -95,7 +100,12 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { +@@ -95,7 +102,12 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count)); } else { @@ -1171,7 +2349,7 @@ } } $this->assertEqual($actual_count, $expected_count, $message); -@@ -109,7 +119,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { +@@ -109,7 +121,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { * @param \Drupal\file\FileInterface $after * File object to compare. */ @@ -1180,7 +2358,7 @@ $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged'); $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged'); $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged'); -@@ -127,7 +137,7 @@ function assertFileUnchanged(FileInterface $before, FileInterface $after) { +@@ -127,7 +139,7 @@ function assertFileUnchanged(FileInterface $before, FileInterface $after) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ @@ -1189,7 +2367,7 @@ $this->assertNotEqual($file1->id(), $file2->id(), t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->id(), '%file2' => $file2->id())), 'Different file'); $this->assertNotEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Different file'); } -@@ -140,28 +150,30 @@ function assertDifferentFile(FileInterface $file1, FileInterface $file2) { +@@ -140,28 +152,28 @@ function assertDifferentFile(FileInterface $file1, FileInterface $file2) { * @param \Drupal\file\FileInterface $file2 * File object to compare. */ @@ -1202,9 +2380,7 @@ /** - * Create a file and save it to the files table and assert that it occurs - * correctly. -+ * Create a file and save it to the files table and assert that. -+ * -+ * it occurs correctly. ++ * Create a file, save to the files table & assert that it occurs correctly. * - * @param $filepath + * @param string $filepath @@ -1385,14 +2561,17 @@ $source = $this->createFile(); $target = $this->createFile(NULL, $contents); diff --git a/core/modules/file/src/Tests/RemoteFileSaveUploadTest.php b/core/modules/file/src/Tests/RemoteFileSaveUploadTest.php -index 81f4340..b087e12 100644 +index 81f4340..31749cc 100644 --- a/core/modules/file/src/Tests/RemoteFileSaveUploadTest.php +++ b/core/modules/file/src/Tests/RemoteFileSaveUploadTest.php -@@ -21,7 +21,7 @@ class RemoteFileSaveUploadTest extends SaveUploadTest { +@@ -21,7 +21,10 @@ class RemoteFileSaveUploadTest extends SaveUploadTest { */ public static $modules = array('file_test'); - protected function setUp() { ++ /** ++ * {@inheritdoc} ++ */ + public function setUp() { parent::setUp(); \Drupal::config('system.file')->set('default_scheme', 'dummy-remote')->save(); @@ -1447,19 +2626,22 @@ $existing = $this->createFile(NULL, $contents); diff --git a/core/modules/file/src/Tests/SaveTest.php b/core/modules/file/src/Tests/SaveTest.php -index ee6c1a3..9d5caac 100644 +index ee6c1a3..63d0509 100644 --- a/core/modules/file/src/Tests/SaveTest.php +++ b/core/modules/file/src/Tests/SaveTest.php -@@ -15,7 +15,7 @@ +@@ -15,7 +15,10 @@ * @group file */ class SaveTest extends FileManagedUnitTestBase { - function testFileSave() { ++ /** ++ * Tests the saving of a file. ++ */ + public function testFileSave() { // Create a new file entity. $file = entity_create('file', array( 'uid' => 1, -@@ -57,8 +57,9 @@ function testFileSave() { +@@ -57,8 +60,9 @@ function testFileSave() { $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was saved correctly.'); @@ -1599,7 +2781,7 @@ $this->assertEqual($file->spaceUsed(NULL, FILE_STATUS_PERMANENT), 370); diff --git a/core/modules/file/src/Tests/UsageTest.php b/core/modules/file/src/Tests/UsageTest.php -index d251bec..e292b02 100644 +index d251bec..7f137a8 100644 --- a/core/modules/file/src/Tests/UsageTest.php +++ b/core/modules/file/src/Tests/UsageTest.php @@ -16,7 +16,7 @@ class UsageTest extends FileManagedUnitTestBase { @@ -1647,6 +2829,15 @@ $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); db_insert('file_usage') +@@ -122,7 +122,7 @@ function testRemoveUsage() { + * We are using UPDATE statements because using the API would set the + * timestamp. + */ +- function createTempFiles() { ++ private function createTempFiles() { + // Temporary file that is old. + $temp_old = file_save_data(''); + db_update('file_managed') @@ -159,7 +159,7 @@ function createTempFiles() { /** * Ensure that temporary files are removed by default. @@ -1698,19 +2889,35 @@ } } diff --git a/core/modules/file/src/Tests/ValidatorTest.php b/core/modules/file/src/Tests/ValidatorTest.php -index b1824b2..dde62a6 100644 +index 4b00a94..21aff71 100644 --- a/core/modules/file/src/Tests/ValidatorTest.php +++ b/core/modules/file/src/Tests/ValidatorTest.php -@@ -24,7 +24,7 @@ class ValidatorTest extends FileManagedUnitTestBase { +@@ -22,24 +22,27 @@ class ValidatorTest extends FileManagedUnitTestBase { + /** + * @var \Drupal\file\Entity\File */ - protected $non_image; +- protected $non_image; ++ protected $nonImage; - protected function setUp() { ++ /** ++ * {@inheritdoc} ++ */ + public function setUp() { parent::setUp(); $this->image = entity_create('file'); -@@ -39,7 +39,7 @@ protected function setUp() { + $this->image->setFileUri('core/misc/druplicon.png'); + $this->image->setFilename(drupal_basename($this->image->getFileUri())); + +- $this->non_image = entity_create('file'); +- $this->non_image->setFileUri('core/assets/vendor/jquery/jquery.js'); +- $this->non_image->setFilename(drupal_basename($this->non_image->getFileUri())); ++ $this->nonImage = entity_create('file'); ++ $this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.js'); ++ $this->nonImage->setFilename(drupal_basename($this->nonImage->getFileUri())); + } + /** * Test the file_validate_extensions() function. */ @@ -1719,7 +2926,7 @@ $file = entity_create('file', array('filename' => 'asdf.txt')); $errors = file_validate_extensions($file, 'asdf txt pork'); $this->assertEqual(count($errors), 0, 'Valid extension accepted.', 'File'); -@@ -50,9 +50,9 @@ function testFileValidateExtensions() { +@@ -50,27 +53,28 @@ function testFileValidateExtensions() { } /** @@ -1731,7 +2938,12 @@ $this->assertTrue(file_exists($this->image->getFileUri()), 'The image being tested exists.', 'File'); $errors = file_validate_is_image($this->image); $this->assertEqual(count($errors), 0, 'No error reported for our image file.', 'File'); -@@ -63,10 +63,11 @@ function testFileValidateIsImage() { + +- $this->assertTrue(file_exists($this->non_image->getFileUri()), 'The non-image being tested exists.', 'File'); +- $errors = file_validate_is_image($this->non_image); ++ $this->assertTrue(file_exists($this->nonImage->getFileUri()), 'The non-image being tested exists.', 'File'); ++ $errors = file_validate_is_image($this->nonImage); + $this->assertEqual(count($errors), 1, 'An error reported for our non-image file.', 'File'); } /** @@ -1739,20 +2951,25 @@ - * The image will be resized if it's too large. + * This ensures the resolution of a specific file is within bounds. + * -+ * The image will be resized if it's too large. ++ * The image will be re-sized if it's too large. */ - function testFileValidateImageResolution() { + public function testFileValidateImageResolution() { // Non-images. - $errors = file_validate_image_resolution($this->non_image); +- $errors = file_validate_image_resolution($this->non_image); ++ $errors = file_validate_image_resolution($this->nonImage); $this->assertEqual(count($errors), 0, 'Should not get any errors for a non-image file.', 'File'); -@@ -105,16 +106,17 @@ function testFileValidateImageResolution() { +- $errors = file_validate_image_resolution($this->non_image, '50x50', '100x100'); ++ $errors = file_validate_image_resolution($this->nonImage, '50x50', '100x100'); + $this->assertEqual(count($errors), 0, 'Do not check the resolution on non files.', 'File'); + + // Minimum size. +@@ -105,16 +109,16 @@ function testFileValidateImageResolution() { drupal_unlink('temporary://druplicon.png'); } else { - // TODO: should check that the error is returned if no toolkit is available. -+ // TODO: should check that the error is returned -+ // if no toolkit is available. ++ // TODO: check that an 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'); } @@ -1767,17 +2984,17 @@ // Create a new file entity. $file = entity_create('file'); -@@ -139,7 +141,7 @@ function testFileValidateNameLength() { +@@ -139,7 +143,7 @@ function testFileValidateNameLength() { /** * Test file_validate_size(). */ - function testFileValidateSize() { + public function testFileValidateSize() { - // Run these tests as a regular user. - $user = entity_create('user', array('uid' => 2, 'name' => $this->randomMachineName())); - $user->enforceIsNew(); + // Create a file with a size of 1000 bytes, and quotas of only 1 byte. + $file = entity_create('file', array('filesize' => 1000)); + $errors = file_validate_size($file, 0, 0); diff --git a/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php b/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php -index 0529090..c61d275 100644 +index 0529090..648cbb2 100644 --- a/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php +++ b/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php @@ -16,6 +16,8 @@ @@ -1789,6 +3006,145 @@ * {@inheritdoc} */ public function getFormId() { +@@ -35,7 +37,7 @@ public function getFormId() { + * (optional) If the form should use #extended. Defaults to TRUE. + * @param bool $multiple + * (optional) If the form should use #multiple. Defaults to FALSE. +- * @param array $default_fids ++ * @param string $default_fids + * (optional) Any default file IDs to use. + */ + public function buildForm(array $form, FormStateInterface $form_state, $tree = TRUE, $extended = TRUE, $multiple = FALSE, $default_fids = NULL) { +diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module +index b1bdeb3..41d579f 100644 +--- a/core/modules/file/tests/file_test/file_test.module ++++ b/core/modules/file/tests/file_test/file_test.module +@@ -43,7 +43,7 @@ function file_test_stream_wrappers() { + * @see file_test_reset() + */ + function file_test_reset() { +- // Keep track of calls to these hooks ++ // Keep track of calls to these hooks. + $results = array( + 'load' => array(), + 'validate' => array(), +@@ -68,11 +68,11 @@ function file_test_reset() { + * Get the arguments passed to invocation of a given hook since + * file_test_reset() was last called. + * +- * @param $op ++ * @param string $op + * One of the hook_file_* operations: 'load', 'validate', 'download', + * 'insert', 'update', 'copy', 'move', 'delete'. + * +- * @return ++ * @return array + * Array of the parameters passed to each call. + * + * @see _file_test_log_call() +@@ -86,7 +86,7 @@ function file_test_get_calls($op) { + /** + * Get an array with the calls for all hooks. + * +- * @return ++ * @return array + * An array keyed by hook name ('load', 'validate', 'download', 'insert', + * 'update', 'copy', 'move', 'delete') with values being arrays of parameters + * passed to each call. +@@ -98,16 +98,16 @@ function file_test_get_all_calls() { + /** + * Store the values passed to a hook invocation. + * +- * @param $op ++ * @param string $op + * One of the hook_file_* operations: 'load', 'validate', 'download', + * 'insert', 'update', 'copy', 'move', 'delete'. +- * @param $args ++ * @param array $args + * Values passed to hook. + * + * @see file_test_get_calls() + * @see file_test_reset() + */ +-function _file_test_log_call($op, $args) { ++function _file_test_log_call($op, array $args) { + if (\Drupal::state()->get('file_test.count_hook_invocations', TRUE)) { + $results = \Drupal::state()->get('file_test.results') ?: array(); + $results[$op][] = $args; +@@ -118,10 +118,10 @@ function _file_test_log_call($op, $args) { + /** + * Load the appropriate return value. + * +- * @param $op ++ * @param string $op + * One of the hook_file_[validate,download] operations. + * +- * @return ++ * @return string + * Value set by file_test_set_return(). + * + * @see file_test_set_return() +@@ -135,9 +135,9 @@ function _file_test_get_return($op) { + /** + * Assign a return value for a given operation. + * +- * @param $op ++ * @param string $op + * One of the hook_file_[validate,download] operations. +- * @param $value ++ * @param string $value + * Value for the hook to return. + * + * @see _file_test_get_return() +@@ -150,7 +150,7 @@ function file_test_set_return($op, $value) { + } + + /** +- * Implements hook_ENTITY_TYPE_load() for file entities. ++ * Implements hook_ENTITY_TYPE_load(). + */ + function file_test_file_load($files) { + foreach ($files as $file) { +@@ -178,14 +178,14 @@ function file_test_file_download($uri) { + } + + /** +- * Implements hook_ENTITY_TYPE_insert() for file entities. ++ * Implements hook_ENTITY_TYPE_insert(). + */ + function file_test_file_insert(File $file) { + _file_test_log_call('insert', array($file->id())); + } + + /** +- * Implements hook_ENTITY_TYPE_update() for file entities. ++ * Implements hook_ENTITY_TYPE_update(). + */ + function file_test_file_update(File $file) { + _file_test_log_call('update', array($file->id())); +@@ -206,7 +206,7 @@ function file_test_file_move(File $file, File $source) { + } + + /** +- * Implements hook_ENTITY_TYPE_predelete() for file entities. ++ * Implements hook_ENTITY_TYPE_predelete(). + */ + function file_test_file_predelete(File $file) { + _file_test_log_call('delete', array($file->id())); +@@ -335,9 +335,10 @@ function file_test_validator(File $file, $errors) { + * When the function is called with no $filepath parameter, the results are + * returned. + * +- * @param $filepath +- * File path +- * @return ++ * @param string $filepath ++ * File path. ++ * ++ * @return array + * If $filepath is NULL, an array of all previous $filepath parameters + */ + function file_test_file_scan_callback($filepath = NULL) { diff --git a/core/modules/file/tests/file_test/src/DummyReadOnlyStreamWrapper.php b/core/modules/file/tests/file_test/src/DummyReadOnlyStreamWrapper.php index d230bc5..0c1690a 100644 --- a/core/modules/file/tests/file_test/src/DummyReadOnlyStreamWrapper.php