diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index 0d795ef..564d06f 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -15,6 +15,7 @@ use Drupal\Core\Ajax\HtmlCommand; use Drupal\editor\Ajax\EditorDialogSave; use Drupal\Core\Ajax\CloseModalDialogCommand; +use Drupal\file\Entity\File; /** * Provides an image dialog for text editors. @@ -206,7 +207,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // attributes. $fid = $form_state->getValue(array('fid', 0)); if (!empty($fid)) { - $file = file_load($fid); + $file = File::load($fid); $file_url = file_create_url($file->getFileUri()); // Transform absolute image URLs to relative image URLs: prevent problems // on multisite set-ups and prevent mixed content errors. diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 825594e..1e6a963 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -659,9 +659,10 @@ function file_cron() { ->condition('changed', REQUEST_TIME - $age, '<') ->range(0, 100) ->execute(); - $files = file_load_multiple($fids); + $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(); @@ -1116,7 +1117,7 @@ function file_managed_file_process($element, FormStateInterface $form_state, $fo // Set some default element properties. $element['#progress_indicator'] = empty($element['#progress_indicator']) ? 'none' : $element['#progress_indicator']; - $element['#files'] = !empty($fids) ? file_load_multiple($fids) : FALSE; + $element['#files'] = !empty($fids) ? File::loadMultiple($fids) : FALSE; $element['#tree'] = TRUE; $ajax_settings = array( @@ -1285,12 +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(); - foreach ($input['fids'] as $fid) { - if ($file = file_load($fid)) { - $fids[] = $file->id(); - } - } + $fids = \Drupal::entityQuery('file') + ->condition('fid', $input['fids'], 'IN') + ->exists('fid') + ->execute(); } } } @@ -1308,12 +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(); - foreach ($default_fids as $fid) { - if ($file = file_load($fid)) { - $fids[] = $file->id(); - } - } + $fids = \Drupal::entityQuery('file') + ->condition('fid', $default_fids, 'IN') + ->exists('fid') + ->execute(); } } @@ -1333,11 +1330,12 @@ function file_managed_file_validate(&$element, FormStateInterface $form_state) { // item were to be deleted. $clicked_button = end($form_state['triggering_element']['#parents']); if ($clicked_button != 'remove_button' && !empty($element['fids']['#value'])) { - $fids = $element['fids']['#value']; - foreach ($fids as $fid) { - if ($file = file_load($fid)) { - if ($file->isPermanent()) { - $references = \Drupal::service('file.usage')->listUsage($file); + $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 = $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']))); } @@ -1548,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/Plugin/Field/FieldFormatter/FileFormatterBase.php b/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php index 3c45fe4..23945fc 100644 --- a/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileFormatterBase.php @@ -8,6 +8,7 @@ namespace Drupal\file\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FormatterBase; +use Drupal\file\Entity\File; /** * Base class for file formatters. @@ -30,7 +31,7 @@ public function prepareView(array $entities_items) { } if ($fids) { - $files = file_load_multiple($fids); + $files = File::loadMultiple($fids); foreach ($entities_items as $items) { foreach ($items as $item) { diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index fdcdb9b..6644e62 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -14,6 +14,7 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; +use Drupal\file\Entity\File; /** * Plugin implementation of the 'file_generic' widget. @@ -323,7 +324,7 @@ public static function validateMultipleCount($element, FormStateInterface $form_ $removed_files = array_slice($values['fids'], $keep); $removed_names = array(); foreach ($removed_files as $fid) { - $file = file_load($fid); + $file = File::load($fid); $removed_names[] = $file->getFilename(); } $args = array('%field' => $field_storage->getFieldName(), '@max' => $field_storage->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names)); diff --git a/core/modules/file/src/Tests/CopyTest.php b/core/modules/file/src/Tests/CopyTest.php index 3a3a727..aec77dd 100644 --- a/core/modules/file/src/Tests/CopyTest.php +++ b/core/modules/file/src/Tests/CopyTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests the file copy function. * @@ -39,7 +41,8 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $fid = $result->id(); + $this->assertFileUnchanged($result, File::load($fid)); } /** @@ -66,9 +69,9 @@ function testExistingRename() { // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->id(), TRUE); - $loaded_target = file_load($target->id(), TRUE); - $loaded_result = file_load($result->id(), TRUE); + $loaded_source = File::load($source->id()); + $loaded_target = File::load($target->id()); + $loaded_result = File::load($result->id()); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -106,9 +109,9 @@ function testExistingReplace() { // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->id(), TRUE); - $loaded_target = file_load($target->id(), TRUE); - $loaded_result = file_load($result->id(), TRUE); + $loaded_source = File::load($source->id()); + $loaded_target = File::load($target->id()); + $loaded_result = File::load($result->id()); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -141,7 +144,7 @@ function testExistingError() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array()); - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $this->assertFileUnchanged($source, File::load($source->id())); + $this->assertFileUnchanged($target, File::load($target->id())); } } diff --git a/core/modules/file/src/Tests/DeleteTest.php b/core/modules/file/src/Tests/DeleteTest.php index f39239f..6ce5c4d 100644 --- a/core/modules/file/src/Tests/DeleteTest.php +++ b/core/modules/file/src/Tests/DeleteTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests the file delete function. * @@ -24,7 +26,7 @@ function testUnused() { $file->delete(); $this->assertFileHooksCalled(array('delete')); $this->assertFalse(file_exists($file->getFileUri()), 'Test file has actually been deleted.'); - $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); + $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); } /** @@ -40,7 +42,7 @@ function testInUse() { $usage = $file_usage->listUsage($file); $this->assertEqual($usage['testing']['test'], array(1 => 1), 'Test file is still in use.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); - $this->assertTrue(file_load($file->id()), 'File still exists in the database.'); + $this->assertTrue(File::load($file->id()), 'File still exists in the database.'); // Clear out the call to hook_file_load(). file_test_reset(); @@ -50,7 +52,7 @@ function testInUse() { $this->assertFileHooksCalled(array('load', 'update')); $this->assertTrue(empty($usage), 'File usage data was removed.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); - $file = file_load($file->id()); + $file = File::load($file->id()); $this->assertTrue($file, 'File still exists in the database.'); $this->assertTrue($file->isTemporary(), 'File is temporary.'); file_test_reset(); @@ -69,6 +71,6 @@ function testInUse() { // 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.'); + $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); } } diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index 281ad34..f174599 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\file\Entity\File; /** * Tests the display of file fields in node and views. @@ -55,7 +56,7 @@ function testNodeDisplay() { // Check that the default formatter is displaying with the file name. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $file_link = array( '#theme' => 'file_link', '#file' => $node_file, diff --git a/core/modules/file/src/Tests/FileFieldPathTest.php b/core/modules/file/src/Tests/FileFieldPathTest.php index 865317a..87449d8 100644 --- a/core/modules/file/src/Tests/FileFieldPathTest.php +++ b/core/modules/file/src/Tests/FileFieldPathTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests that files are uploaded to proper locations. * @@ -27,7 +29,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Change the path to contain multiple subdirectories. @@ -38,7 +40,9 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id, TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($node->{$field_name}->target_id)); + $node_file = File::load($node->{$field_name}->target_id); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Check the path when used with tokens. @@ -50,7 +54,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/src/Tests/FileFieldRSSContentTest.php b/core/modules/file/src/Tests/FileFieldRSSContentTest.php index db265c2..e66a54c 100644 --- a/core/modules/file/src/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/src/Tests/FileFieldRSSContentTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Ensure that files added to nodes appear correctly in RSS feeds. * @@ -59,7 +61,7 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); diff --git a/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php index b45b200..c74d126 100644 --- a/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests creating and deleting revisions with files attached. * @@ -38,7 +40,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node = node_load($nid, TRUE); - $node_file_r1 = file_load($node->{$field_name}->target_id); + $node_file_r1 = File::load($node->{$field_name}->target_id); $node_vid_r1 = $node->getRevisionId(); $this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.'); @@ -47,7 +49,7 @@ function testRevisions() { // Upload another file to the same node in a new revision. $this->replaceNodeFile($test_file, $field_name, $nid); $node = node_load($nid, TRUE); - $node_file_r2 = file_load($node->{$field_name}->target_id); + $node_file_r2 = File::load($node->{$field_name}->target_id); $node_vid_r2 = $node->getRevisionId(); $this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.'); @@ -55,7 +57,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $current_file = file_load($node->{$field_name}->target_id); + $current_file = File::load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $current_file->id(), 'Original file still in place after replacing file in new revision.'); $this->assertFileExists($node_file_r1, 'Original file still in place after replacing file in new revision.'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision'); @@ -65,7 +67,7 @@ function testRevisions() { // Check that the file is still the same as the previous revision. $this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node = node_load($nid, TRUE); - $node_file_r3 = file_load($node->{$field_name}->target_id); + $node_file_r3 = File::load($node->{$field_name}->target_id); $node_vid_r3 = $node->getRevisionId(); $this->assertEqual($node_file_r2->id(), $node_file_r3->id(), 'Previous revision file still in place after creating a new revision without a new file.'); $this->assertFileIsPermanent($node_file_r3, 'New revision file is permanent.'); @@ -73,7 +75,7 @@ function testRevisions() { // Revert to the first revision and check that the original file is active. $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node = node_load($nid, TRUE); - $node_file_r4 = file_load($node->{$field_name}->target_id); + $node_file_r4 = File::load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $node_file_r4->id(), 'Original revision file still in place after reverting to the original revision.'); $this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.'); diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index b0efe1b..058c07e 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -11,6 +11,7 @@ use Drupal\field\Entity\FieldInstanceConfig; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; +use Drupal\file\Entity\File; /** * Provides methods specifically for testing File module's field handling. @@ -210,7 +211,7 @@ function assertFileExists($file, $message = NULL) { */ function assertFileEntryExists($file, $message = NULL) { $this->container->get('entity.manager')->getStorage('file')->resetCache(); - $db_file = file_load($file->id()); + $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())); $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message); } @@ -229,7 +230,7 @@ function assertFileNotExists($file, $message = NULL) { function assertFileEntryNotExists($file, $message) { $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); + $this->assertFalse(File::load($file->id()), $message); } /** diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index 182ffad..5d9d4fe 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldInstanceConfig; +use Drupal\file\Entity\File; /** * Tests validation functions such as file type, max file size, max size per @@ -43,7 +44,7 @@ function testRequired() { $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.'); @@ -60,7 +61,7 @@ function testRequired() { // Create a new node with the uploaded file into the multivalue field. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.'); } @@ -90,7 +91,7 @@ function testFileMaxSize() { // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); @@ -106,7 +107,7 @@ function testFileMaxSize() { // Upload the big file successfully. $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); } @@ -128,7 +129,7 @@ function testFileExtension() { // Check that the file can be uploaded with no extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.'); @@ -146,7 +147,7 @@ function testFileExtension() { // Check that the file can be uploaded with extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.'); } diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index 9ae0940..7bdb9b1 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -9,6 +9,7 @@ use Drupal\comment\Entity\Comment; use Drupal\field\Entity\FieldInstanceConfig; +use Drupal\file\Entity\File; /** * Tests the file field widget, single and multi-valued, with and without AJAX, @@ -42,7 +43,7 @@ function testSingleValuedWidget() { // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. @@ -215,7 +216,7 @@ function testPrivateFileSetting() { $this->drupalPostForm("admin/structure/types/manage/$type_name/fields/$instance->id/storage", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the private file is available to the user who uploaded it. diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index e327ed2..b5b1191 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests file listing page functionality. * @@ -94,7 +96,7 @@ function testFileListingPages() { $this->drupalGet('admin/content/files'); foreach ($nodes as $node) { - $file = entity_load('file', $node->file->target_id); + $file = File::load($node->file->target_id); $this->assertText($file->getFilename()); $this->assertLinkByHref(file_create_url($file->getFileUri())); $this->assertLinkByHref('admin/content/files/usage/' . $file->id()); @@ -108,11 +110,11 @@ function testFileListingPages() { $nodes[1]->save(); $this->drupalGet('admin/content/files'); - $file = entity_load('file', $orphaned_file); + $file = File::load($orphaned_file); $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); - $file = entity_load('file', $used_file); + $file = File::load($used_file); $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); @@ -121,7 +123,7 @@ function testFileListingPages() { // Test file usage page. foreach ($nodes as $node) { - $file = entity_load('file', $node->file->target_id); + $file = File::load($node->file->target_id); $usage = $file_usage->listUsage($file); $this->drupalGet('admin/content/files/usage/' . $file->id()); $this->assertResponse(200); diff --git a/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php index 5599667..13b24d1 100644 --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\file\Tests; + use Drupal\file\Entity\File; use Drupal\node\Entity\Node; @@ -46,7 +47,7 @@ function testPrivateFile() { $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = File::load($node->{$field_name}->target_id); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 36fe888..679dd48 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\Component\Utility\String; +use Drupal\file\Entity\File; /** * Generates text using placeholders for dummy content to check file token @@ -38,7 +39,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node = node_load($nid, TRUE); - $file = file_load($node->{$field_name}->target_id); + $file = File::load($node->{$field_name}->target_id); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/file/src/Tests/LoadTest.php b/core/modules/file/src/Tests/LoadTest.php index 7c593cb..434841d 100644 --- a/core/modules/file/src/Tests/LoadTest.php +++ b/core/modules/file/src/Tests/LoadTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests the file_load() function. * @@ -17,7 +19,7 @@ class LoadTest extends FileManagedUnitTestBase { * Try to load a non-existent file by fid. */ function testLoadMissingFid() { - $this->assertFalse(file_load(-1), 'Try to load an invalid fid fails.'); + $this->assertFalse(File::load(-1), 'Try to load an invalid fid fails.'); $this->assertFileHooksCalled(array()); } @@ -46,9 +48,9 @@ function testSingleValues() { // Create a new file entity from scratch so we know the values. $file = $this->createFile('druplicon.txt', NULL, 'public'); - $by_fid_file = file_load($file->id()); + $by_fid_file = File::load($file->id()); $this->assertFileHookCalled('load'); - $this->assertTrue(is_object($by_fid_file), 'file_load() returned an object.'); + $this->assertTrue(is_object($by_fid_file), 'File::load() returned an object.'); $this->assertEqual($by_fid_file->id(), $file->id(), 'Loading by fid got the same fid.', 'File'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), 'Loading by fid got the correct filename.', 'File'); @@ -75,9 +77,9 @@ function testMultiple() { // Load by fid. file_test_reset(); - $by_fid_files = file_load_multiple(array($file->id())); + $by_fid_files = File::loadMultiple(array($file->id())); $this->assertFileHooksCalled(array()); - $this->assertEqual(1, count($by_fid_files), 'file_load_multiple() returned an array of the correct size.'); + $this->assertEqual(1, count($by_fid_files), 'File::loadMultiple() returned an array of the correct size.'); $by_fid_file = reset($by_fid_files); $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); diff --git a/core/modules/file/src/Tests/MoveTest.php b/core/modules/file/src/Tests/MoveTest.php index 9b1bfc2..7a76637 100644 --- a/core/modules/file/src/Tests/MoveTest.php +++ b/core/modules/file/src/Tests/MoveTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests the file move function. * @@ -38,7 +40,9 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_file = file_load($result->id(), TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $loaded_file = File::load($result->id()); $this->assertTrue($loaded_file, 'File can be loaded from the database.'); $this->assertFileUnchanged($result, $loaded_file); } @@ -66,14 +70,18 @@ function testExistingRename() { $this->assertFileHooksCalled(array('move', 'load', 'update')); // Compare the returned value to what made it into the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, File::load($result->id())); // The target file should not have been altered. - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage->resetCache(array($target->id())); + $this->assertFileUnchanged($target, File::load($target->id())); // Make sure we end up with two distinct files afterwards. $this->assertDifferentFile($target, $result); // Compare the source and results. - $loaded_source = file_load($source->id(), TRUE); + $file_storage->resetCache(array($source->id())); + $loaded_source = File::load($source->id()); $this->assertEqual($loaded_source->id(), $result->id(), "Returned file's id matches the source."); $this->assertNotEqual($loaded_source->getFileUri(), $source->getFileUri(), 'Returned file path has changed from the original.'); } @@ -102,7 +110,9 @@ function testExistingReplace() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_result = file_load($result->id(), TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $loaded_result = File::load($result->id()); $this->assertFileUnchanged($result, $loaded_result); // Check that target was re-used. $this->assertSameFile($target, $loaded_result); @@ -129,7 +139,9 @@ function testExistingReplaceSelf() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($source->id())); + $this->assertFileUnchanged($source, File::load($source->id())); } /** @@ -156,7 +168,10 @@ function testExistingError() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $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())); } } diff --git a/core/modules/file/src/Tests/SaveDataTest.php b/core/modules/file/src/Tests/SaveDataTest.php index 8368e0b..73f098f 100644 --- a/core/modules/file/src/Tests/SaveDataTest.php +++ b/core/modules/file/src/Tests/SaveDataTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests the file_save_data() function. * @@ -32,7 +34,9 @@ function testWithoutFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -57,7 +61,9 @@ function testWithFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -81,11 +87,14 @@ function testExistingRename() { $this->assertFileHooksCalled(array('insert')); // Ensure that the existing file wasn't overwritten. + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($existing->id())); $this->assertDifferentFile($existing, $result); - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $this->assertFileUnchanged($existing, File::load($existing->id())); // Verify that was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -112,7 +121,9 @@ function testExistingReplace() { $this->assertSameFile($existing, $result); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -131,6 +142,8 @@ function testExistingError() { $this->assertFileHooksCalled(array()); // Ensure that the existing file wasn't overwritten. - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($existing->id())); + $this->assertFileUnchanged($existing, File::load($existing->id())); } } diff --git a/core/modules/file/src/Tests/SaveTest.php b/core/modules/file/src/Tests/SaveTest.php index a390b54..70c5ed7 100644 --- a/core/modules/file/src/Tests/SaveTest.php +++ b/core/modules/file/src/Tests/SaveTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\Core\Language\LanguageInterface; +use Drupal\file\Entity\File; /** * File saving tests. @@ -35,7 +36,7 @@ function testFileSave() { $this->assertFileHooksCalled(array('insert')); $this->assertTrue($file->id() > 0, 'A new file ID is set when saving a new file to the database.', 'File'); - $loaded_file = file_load($file->id()); + $loaded_file = File::load($file->id()); $this->assertNotNull($loaded_file, 'Record exists in the database.'); $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($file->getSize(), filesize($file->getFileUri()), 'File size was set correctly.', 'File'); @@ -53,7 +54,7 @@ function testFileSave() { $this->assertEqual($file->id(), $file->id(), 'The file ID of an existing file is not changed when updating the database.', 'File'); $this->assertTrue($file->getChangedTime() >= $file->getChangedTime(), "Timestamp didn't go backwards.", 'File'); - $loaded_file = file_load($file->id()); + $loaded_file = File::load($file->id()); $this->assertNotNull($loaded_file, 'Record still exists in the database.', 'File'); $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was saved correctly.'); diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php index 363b675..59fd116 100644 --- a/core/modules/file/src/Tests/SaveUploadTest.php +++ b/core/modules/file/src/Tests/SaveUploadTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** * Tests the file_save_upload() function. * @@ -65,7 +67,7 @@ function setUp() { function testNormal() { $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); $this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.'); - $file1 = file_load($max_fid_after); + $file1 = File::load($max_fid_after); $this->assertTrue($file1, 'Loaded the file.'); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file1->getMimeType(), 0, 5), 'image', 'A MIME type was set.'); @@ -84,13 +86,13 @@ function testNormal() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('validate', 'insert')); - $file2 = file_load($max_fid_after); + $file2 = File::load($max_fid_after); $this->assertTrue($file2, 'Loaded the file'); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file2->getMimeType(), 0, 5), 'image', 'A MIME type was set.'); - // Load both files using file_load_multiple(). - $files = file_load_multiple(array($file1->id(), $file2->id())); + // Load both files using File::loadMultiple(). + $files = File::loadMultiple(array($file1->id(), $file2->id())); $this->assertTrue(isset($files[$file1->id()]), 'File was loaded successfully'); $this->assertTrue(isset($files[$file2->id()]), 'File was loaded successfully'); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index a6ce171..eb89f2a 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -365,7 +365,7 @@ function image_entity_presave(EntityInterface $entity) { if ($fid) { $original_fid = isset($entity->original) ? $entity->original->settings['default_image']['fid'] : NULL; if ($fid != $original_fid) { - $file = file_load($fid); + $file = File::load($fid); if ($file) { $image = \Drupal::service('image.factory')->get($file->getFileUri()); $entity->settings['default_image']['width'] = $image->getWidth(); @@ -395,7 +395,7 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st $fid_new = $field_storage->settings['default_image']['fid']; $fid_old = $prior_field_storage->settings['default_image']['fid']; - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_new = $fid_new ? File::load($fid_new) : FALSE; if ($fid_new != $fid_old) { @@ -407,7 +407,7 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st } // Is there an old file? - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = File::load($fid_old))) { \Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_storage->uuid()); } } @@ -436,7 +436,7 @@ function image_field_instance_config_update(FieldInstanceConfigInterface $field_ $fid_old = $prior_instance->settings['default_image']['fid']; // If the old and new files do not match, update the default accordingly. - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_new = $fid_new ? File::load($fid_new) : FALSE; if ($fid_new != $fid_old) { // Save the new file, if present. if ($file_new) { @@ -445,7 +445,7 @@ function image_field_instance_config_update(FieldInstanceConfigInterface $field_ \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field_instance->uuid()); } // Delete the old file, if present. - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = File::load($fid_old))) { \Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_instance->uuid()); } } @@ -469,7 +469,7 @@ function image_field_storage_config_delete(FieldStorageConfigInterface $field) { // The value of a managed_file element can be an array if #extended == TRUE. $fid = $field->settings['default_image']['fid']; - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = File::load($fid))) { \Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid()); } } @@ -488,7 +488,7 @@ function image_field_instance_config_delete(FieldInstanceConfigInterface $field_ $fid = $field_instance->settings['default_image']['fid']; // Remove the default image when the instance is deleted. - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = File::load($fid))) { \Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field_instance->uuid()); } } diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php index e99d8eb..67c586d 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php @@ -9,6 +9,7 @@ use Drupal\field\FieldInstanceConfigInterface; use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase; +use Drupal\file\Entity\File; /** * Base class for image file formatters. @@ -32,7 +33,7 @@ public function prepareView(array $entities_items) { $default_image = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('default_image'); } - if (!empty($default_image['fid']) && ($file = file_load($default_image['fid']))) { + if (!empty($default_image['fid']) && ($file = File::load($default_image['fid']))) { $items->setValue(array(array( 'is_default' => TRUE, 'alt' => $default_image['alt'], diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index d998883..a5ed89b 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -8,6 +8,7 @@ namespace Drupal\image\Tests; use Drupal\image\ImageStyleInterface; +use Drupal\file\Entity\File; /** * Tests creation, deletion, and editing of image styles and effects. @@ -289,7 +290,7 @@ function testStyleReplacement() { // Get node field original image URI. $fid = $node->get($field_name)->target_id; - $original_uri = file_load($fid)->getFileUri(); + $original_uri = File::load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); @@ -423,7 +424,7 @@ function testConfigImport() { // Get node field original image URI. $fid = $node->get($field_name)->target_id; - $original_uri = file_load($fid)->getFileUri(); + $original_uri = File::load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 77d112b..0646407 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\file\Entity\File; /** * Tests the display of image fields. @@ -60,7 +61,7 @@ function _testImageFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); + $image_uri = File::load($node->{$field_name}->target_id)->getFileUri(); $image = array( '#theme' => 'image', '#uri' => $image_uri, @@ -198,7 +199,7 @@ function testImageFieldSettings() { $node = node_load($nid, TRUE); $image_style = array( '#theme' => 'image_style', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => File::load($node->{$field_name}->target_id)->getFileUri(), '#width' => 220, '#height' => 110, '#style_name' => 'medium', @@ -209,7 +210,7 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image = array( '#theme' => 'image', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => File::load($node->{$field_name}->target_id)->getFileUri(), '#alt' => $this->randomMachineName(), '#title' => $this->randomMachineName(), '#width' => 40, @@ -294,7 +295,7 @@ function testImageFieldDefaultImage() { \Drupal::entityManager()->clearCachedFieldDefinitions(); $field_storage = FieldStorageConfig::loadByName('node', $field_name); $default_image = $field_storage->getSetting('default_image'); - $file = file_load($default_image['fid']); + $file = File::load($default_image['fid']); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.'); $image = array( '#theme' => 'image', @@ -316,7 +317,7 @@ function testImageFieldDefaultImage() { $node = node_load($nid, TRUE); $image = array( '#theme' => 'image', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => File::load($node->{$field_name}->target_id)->getFileUri(), '#width' => 40, '#height' => 20, ); @@ -353,7 +354,7 @@ function testImageFieldDefaultImage() { $private_field_storage = FieldStorageConfig::loadByName('node', $private_field_name); $default_image = $private_field_storage->getSetting('default_image'); - $file = file_load($default_image['fid']); + $file = File::load($default_image['fid']); $this->assertEqual('private', file_uri_scheme($file->getFileUri()), 'Default image uses private:// scheme.'); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.'); // Create a new node with no image attached and ensure that default private diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php index 48645c1..0db7ce6 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -9,6 +9,7 @@ use Drupal\migrate\MigrateExecutable; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; +use Drupal\file\Entity\File; /** * file migration. @@ -46,7 +47,7 @@ protected function setUp() { */ public function testFiles() { /** @var \Drupal\file\FileInterface $file */ - $file = entity_load('file', 1); + $file = File::load(1); $this->assertEqual($file->getFilename(), 'Image1.png'); $this->assertEqual($file->getSize(), 39325); $this->assertEqual($file->getFileUri(), 'public://image-1.png'); @@ -66,7 +67,7 @@ public function testFiles() { $executable = new MigrateExecutable($migration, $this); $executable->import(); - $file = entity_load('file', 2); + $file = File::load(2); $this->assertEqual($file->getFileUri(), 'public://core/modules/simpletest/files/image-2.jpg'); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php index b559836..a7ed31e 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php @@ -9,6 +9,7 @@ use Drupal\migrate\MigrateExecutable; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; +use Drupal\file\Entity\File; /** * User pictures migration. @@ -48,8 +49,7 @@ public function testUserPictures() { foreach (entity_load('migration', 'd6_user_picture_file')->getIdMap() as $destination_ids) { $file_ids[] = reset($destination_ids); } - $files = entity_load_multiple('file', $file_ids); - /** @var \Drupal\file\FileInterface $file */ + $files = File::loadMultiple($file_ids); $file = array_shift($files); $this->assertEqual($file->getFilename(), 'image-test.jpg'); $this->assertEqual($file->getFileUri(), 'public://image-test.jpg'); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserTest.php index 2c72e19..d6b1fc3 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Database\Database; use Drupal\migrate\MigrateExecutable; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; +use Drupal\file\Entity\File; /** * Users migration. @@ -174,7 +175,7 @@ public function testUser() { // We have one empty picture in the data so don't try load that. if (!empty($source->picture)) { // Test the user picture. - $file = file_load($user->user_picture->target_id); + $file = File::load($user->user_picture->target_id); $this->assertEqual($file->getFilename(), basename($source->picture)); } diff --git a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php index 40a65da..bf337ad 100644 --- a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php @@ -8,6 +8,7 @@ namespace Drupal\rdf\Tests; use Drupal\file\Tests\FileFieldTestBase; +use Drupal\file\Entity\File; /** * Tests the RDFa markup of filefields. @@ -66,7 +67,7 @@ public function setUp() { $nid = $this->uploadNodeFile($test_file, $this->fieldName, $type_name); $this->node = node_load($nid, TRUE); - $this->file = file_load($this->node->{$this->fieldName}->target_id); + $this->file = File::load($this->node->{$this->fieldName}->target_id); } diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php index 300fac5..7f3fe7e 100644 --- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php @@ -8,6 +8,7 @@ namespace Drupal\rdf\Tests; use Drupal\image\Tests\ImageFieldTestBase; +use Drupal\file\Entity\File; /** * Tests the RDFa markup of imagefields. @@ -66,7 +67,7 @@ public function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article'); $this->node = node_load($nid); - $this->file = file_load($this->node->{$this->fieldName}->target_id); + $this->file = File::load($this->node->{$this->fieldName}->target_id); } /** diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index 27450e6..4a4ffba 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -9,6 +9,7 @@ use Drupal\breakpoint\Entity\Breakpoint; use Drupal\image\Tests\ImageFieldTestBase; +use Drupal\file\Entity\File; /** * Tests responsive image display formatter. @@ -116,7 +117,7 @@ public function _testResponsiveImageFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); + $image_uri = File::load($node->{$field_name}->target_id)->getFileUri(); $image = array( '#theme' => 'image', '#uri' => $image_uri, diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 56bbd98..c273f36 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -11,6 +11,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Database\Database; use Drupal\Core\Language\LanguageInterface; +use Drupal\file\Entity\File; /** * Tests the invocation of hooks when creating, inserting, loading, updating or @@ -251,7 +252,7 @@ public function testFileHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $file = file_load($file->id()); + $file = File::load($file->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type file', diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module index c7f20c3..3fc7d15 100644 --- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module +++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\file\Entity\File; /** * Implements hook_entity_create(). diff --git a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php index 7d8589e..9364e72 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\file\Entity\File; + /** * Tests access checks of private image fields. * @@ -83,7 +85,7 @@ public function testTaxonomyImageAccess() { // Create a user that should have access to the file and one that doesn't. $access_user = $this->drupalCreateUser(array('access content')); $no_access_user = $this->drupalCreateUser(); - $image = file_load($term->field_test->target_id); + $image = File::load($term->field_test->target_id); $this->drupalLogin($access_user); $this->drupalGet(file_create_url($image->getFileUri())); $this->assertResponse(200, 'Private image on term is accessible with right permission'); diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index b1825a5..df3b20c 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -8,6 +8,7 @@ namespace Drupal\user\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\file\Entity\File; /** * Tests user picture functionality. @@ -71,7 +72,9 @@ function testCreateDeletePicture() { \Drupal::service('cron')->run(); // Verify that the image has been deleted. - $this->assertFalse(file_load($file->id(), TRUE), 'File was removed from the database.'); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($file->id())); + $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); // Clear out PHP's file stat cache so we see the current value. clearstatcache(TRUE, $file->getFileUri()); $this->assertFalse(is_file($file->getFileUri()), 'File was removed from the file system.'); @@ -128,6 +131,8 @@ function saveUserPicture($image) { // Load actual user data from database. $account = user_load($this->web_user->id(), TRUE); - return file_load($account->user_picture->target_id, TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($account->user_picture->target_id)); + return File::load($account->user_picture->target_id); } }