diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 96c5d08..1e6a963 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -660,8 +660,9 @@ function file_cron() { ->range(0, 100) ->execute(); $files = File::loadMultiple($fids); + $file_usage = \Drupal::service('file.usage'); foreach ($files as $file) { - $references = \Drupal::service('file.usage')->listUsage($file); + $references = $file_usage->listUsage($file); if (empty($references)) { if (file_exists($file->getFileUri())) { $file->delete(); @@ -1285,7 +1286,10 @@ function file_managed_file_value(&$element, $input, FormStateInterface $form_sta // Load files if the FIDs have changed to confirm they exist. if (!empty($input['fids'])) { - $fids = array_keys(File::loadMultiple($input['fids'])); + $fids = \Drupal::entityQuery('file') + ->condition('fid', $input['fids'], 'IN') + ->exists('fid') + ->execute(); } } } @@ -1303,7 +1307,10 @@ function file_managed_file_value(&$element, $input, FormStateInterface $form_sta // Confirm that the file exists when used as a default value. if (!empty($default_fids)) { - $fids = array_keys(File::loadMultiple($default_fids)); + $fids = \Drupal::entityQuery('file') + ->condition('fid', $default_fids, 'IN') + ->exists('fid') + ->execute(); } } @@ -1324,10 +1331,11 @@ function file_managed_file_validate(&$element, FormStateInterface $form_state) { $clicked_button = end($form_state['triggering_element']['#parents']); if ($clicked_button != 'remove_button' && !empty($element['fids']['#value'])) { $files = File::loadMultiple($element['fids']['#value']); + $file_usage = \Drupal::service('file.usage'); foreach ($element['fids']['#value'] as $fid) { if (!empty($files[$fid])) { if ($files[$fid]->isPermanent()) { - $references = \Drupal::service('file.usage')->listUsage($files[$fid]); + $references = $file_usage->listUsage($files[$fid]); if (empty($references)) { form_error($element, $form_state, t('The file used in the !name field may not be referenced.', array('!name' => $element['#title']))); } @@ -1538,7 +1546,7 @@ function template_preprocess_file_link(&$variables) { $icon_directory = $variables['icon_directory']; $url = file_create_url($file->getFileUri()); - $file_entity = ($file instanceof File) ? $file : File::load($file->fid); + $file_entity = ($file instanceof FileInterface) ? $file : File::load($file->fid); // Human-readable names, for use as text-alternatives to icons. $mime_name = array( diff --git a/core/modules/file/src/Tests/CopyTest.php b/core/modules/file/src/Tests/CopyTest.php index 862ab57..aec77dd 100644 --- a/core/modules/file/src/Tests/CopyTest.php +++ b/core/modules/file/src/Tests/CopyTest.php @@ -42,9 +42,6 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. $fid = $result->id(); - $file_storage = $this->container->get('entity.manager')->getStorage('file'); - $file_storage->resetCache(array($fid)); - $this->assertFileUnchanged($result, File::load($fid)); } @@ -72,12 +69,8 @@ function testExistingRename() { // Load all the affected files to check the changes that actually made it // to the database. - $file_storage = $this->container->get('entity.manager')->getStorage('file'); - $file_storage->resetCache(array($source->id())); $loaded_source = File::load($source->id()); - $file_storage->resetCache(array($target->id())); $loaded_target = File::load($target->id()); - $file_storage->resetCache(array($result->id())); $loaded_result = File::load($result->id()); // Verify that the source file wasn't changed. @@ -116,12 +109,8 @@ function testExistingReplace() { // Load all the affected files to check the changes that actually made it // to the database. - $file_storage = $this->container->get('entity.manager')->getStorage('file'); - $file_storage->resetCache(array($source->id())); $loaded_source = File::load($source->id()); - $file_storage->resetCache(array($target->id())); $loaded_target = File::load($target->id()); - $file_storage->resetCache(array($result->id())); $loaded_result = File::load($result->id()); // Verify that the source file wasn't changed. @@ -155,11 +144,7 @@ function testExistingError() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array()); - $file_storage = $this->container->get('entity.manager')->getStorage('file'); - - $file_storage->resetCache(array($source->id())); $this->assertFileUnchanged($source, File::load($source->id())); - $file_storage->resetCache(array($target->id())); $this->assertFileUnchanged($target, File::load($target->id())); } }