diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index 8b37f723feb542a58c99d9cb777f0ed202217f27..9c2feb5a37dd2ce85d21f0b106f21df630270079 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -15,12 +15,40 @@ use Drupal\Core\Ajax\HtmlCommand; use Drupal\editor\Ajax\EditorDialogSave; use Drupal\Core\Ajax\CloseModalDialogCommand; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Entity\EntityStorageInterface; /** * Provides an image dialog for text editors. */ class EditorImageDialog extends FormBase { + /** + * The file storage service. + * + * @var \Drupal\Core\Entity\EntityStorageInterface + */ + protected $fileStorage; + + /** + * Constructs a form object for image dialog. + * + * @param \Drupal\Core\Entity\EntityStorageInterface $file_storage + * The file storage service. + */ + public function __construct(EntityStorageInterface $file_storage) { + $this->fileStorage = $file_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.manager')->getStorage('file') + ); + } + /** * {@inheritdoc} */ @@ -208,7 +236,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // attributes and set data-entity-type to 'file'. $fid = $form_state->getValue(array('fid', 0)); if (!empty($fid)) { - $file = file_load($fid); + $file = $this->fileStorage->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 01b4ddb7134bcb5c7787ddfec12603d7e90470f3..2458582dcafdf7db4a1698c68f85e60c6e9d49da 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -631,6 +631,7 @@ function file_file_download($uri) { */ function file_cron() { $age = \Drupal::config('system.file')->get('temporary_maximum_age'); + $file_storage = \Drupal::entityManager()->getStorage('file'); // Only delete temporary files if older than $age. Note that automatic cleanup // is disabled if $age set to 0. @@ -640,7 +641,7 @@ function file_cron() { ->condition('changed', REQUEST_TIME - $age, '<') ->range(0, 100) ->execute(); - $files = file_load_multiple($fids); + $files = $file_storage->loadMultiple($fids); foreach ($files as $file) { $references = \Drupal::service('file.usage')->listUsage($file); if (empty($references)) { @@ -1225,7 +1226,7 @@ function template_preprocess_file_link(&$variables) { $file = $variables['file']; $options = array(); - $file_entity = ($file instanceof File) ? $file : file_load($file->fid); + $file_entity = ($file instanceof File) ? $file : File::load($file->fid); $url = file_create_url($file_entity->getFileUri()); $mime_type = $file->getMimeType(); diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index fbc30d89e2d0c67f34e04d30e2c9d6e92af5b60a..137d841217d51206fca120ccdbb18ca1c67b5b66 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -20,6 +20,7 @@ use Drupal\Core\Url; use Drupal\file\Element\ManagedFile; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\file\Entity\File; /** * Plugin implementation of the 'file_generic' widget. @@ -346,7 +347,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 4b944490120c8f365fba0282492e91df1e87af2f..68c589bef4e79cccf6bad590962276adff75edf4 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,7 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -66,9 +68,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 +108,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 +143,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 f89dfbff8b24ec1cb0901b2ea571d6bf95f9e743..1ec037669939d83065ca9521b5d981ce8f4abc65 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 f4db76525f0dbefe0c581bdb580704ec7f153ed3..5cbb9707d5dde91374f7183bd7eb31f71a68ac09 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. @@ -57,7 +58,7 @@ function testNodeDisplay() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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 d7e034607eebe27d10017393571d71f27a3fcded..346fc7a27d2a4cd16e69fe45972cfd2068dae3d0 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. * @@ -29,7 +31,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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. @@ -41,7 +43,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id, TRUE); + $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. @@ -54,7 +56,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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->adminUser); diff --git a/core/modules/file/src/Tests/FileFieldRSSContentTest.php b/core/modules/file/src/Tests/FileFieldRSSContentTest.php index 7455301c6bf278e46b975ef5d125112af2e7b620..5314a7bbb39e21653f9b3061802c7b8b7568e36a 100644 --- a/core/modules/file/src/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/src/Tests/FileFieldRSSContentTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\node\Entity\Node; +use Drupal\file\Entity\File; /** * Ensure that files added to nodes appear correctly in RSS feeds. @@ -63,7 +64,7 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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 bb3cf8a509cd8b83b8b9a75d029f3a9d48b3cb3e..7da2a90724fea069af793c1f6b49c21c45fd51a7 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. * @@ -40,7 +42,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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.'); @@ -50,7 +52,7 @@ function testRevisions() { $this->replaceNodeFile($test_file, $field_name, $nid); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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.'); @@ -58,7 +60,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'); @@ -69,7 +71,7 @@ function testRevisions() { $this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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.'); @@ -78,7 +80,7 @@ function testRevisions() { $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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 4f8d9c8d8006ffe94e812ff11fc00241482fee2d..c03da58d18ccdf62b69e87eb2632b106ea651303 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\FieldConfig; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; +use Drupal\file\Entity\File; /** * Provides methods specifically for testing File module's field handling. @@ -45,7 +46,8 @@ function getTestFile($type_name, $size = NULL) { // Get a file to upload. $file = current($this->drupalGetTestFiles($type_name, $size)); - // Add a filesize property to files as would be read by file_load(). + // Add a filesize property to files as would be read by + // \Drupal\file\Entity\File::load(). $file->filesize = filesize($file->uri); return entity_create('file', (array) $file); @@ -221,7 +223,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); } @@ -240,7 +242,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 d98f6cd6c6d473958f29202c78a7f0e1f58f4002..46e34ee27b62a258bb2e572aa579f2e5cf38ee2e 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\FieldConfig; +use Drupal\file\Entity\File; /** * Tests validation functions such as file type, max file size, max size per @@ -44,7 +45,7 @@ function testRequired() { $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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.'); @@ -63,7 +64,7 @@ function testRequired() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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.'); } @@ -95,7 +96,7 @@ function testFileMaxSize() { $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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))); @@ -112,7 +113,7 @@ function testFileMaxSize() { $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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())))); } @@ -136,7 +137,7 @@ function testFileExtension() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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.'); @@ -155,7 +156,7 @@ function testFileExtension() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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 c03e118ccb03725f660c8610d9a95158afa80a14..b696596ef39e736bf984f100fbd485f762826f6f 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -12,6 +12,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field_ui\Tests\FieldUiTestTrait; use Drupal\user\RoleInterface; +use Drupal\file\Entity\File; /** * Tests the file field widget, single and multi-valued, with and without AJAX, @@ -58,7 +59,7 @@ function testSingleValuedWidget() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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. @@ -238,7 +239,7 @@ function testPrivateFileSetting() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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 b752c3ffd012bfc134adca3ab9122f2d32573729..72b2378fc383847b1892b59c4e3b26f6f47e5ba8 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests; use Drupal\node\Entity\Node; +use Drupal\file\Entity\File; /** * Tests file listing page functionality. @@ -103,7 +104,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()); @@ -117,11 +118,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); @@ -130,7 +131,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/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 1f0d733f6ef858805adc4d539c69553cc403da5c..f5f478a83e2bfd53a52cba8e954aaf65770b2e8f 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\SafeMarkup; +use Drupal\file\Entity\File; /** * Generates text using placeholders for dummy content to check file token @@ -40,7 +41,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $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 a9cf13187944ddb48072bac562335fac7d385ef8..7a0fde9ce6834fc7578cdccfa2b273b1980e67f9 100644 --- a/core/modules/file/src/Tests/LoadTest.php +++ b/core/modules/file/src/Tests/LoadTest.php @@ -7,8 +7,10 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; + /** - * Tests the file_load() function. + * Tests \Drupal\file\Entity\File::load(). * * @group file */ @@ -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()); } @@ -45,10 +47,9 @@ function testLoadInvalidStatus() { 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), '\Drupal\file\Entity\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'); @@ -68,16 +69,16 @@ function testMultiple() { file_test_reset(); $by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->getFileUri())); $this->assertFileHookCalled('load'); - $this->assertEqual(1, count($by_path_files), 'file_load_multiple() returned an array of the correct size.'); + $this->assertEqual(1, count($by_path_files), 'entity_load_multiple_by_properties() returned an array of the correct size.'); $by_path_file = reset($by_path_files); $this->assertTrue($by_path_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.'); $this->assertEqual($by_path_file->id(), $file->id(), 'Loading by filepath got the correct fid.', 'File'); // 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), '\Drupal\file\Entity\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 f3380db06bb02492a522ec46170fb06bd9e40166..817799293b8d6018f37dfd4df8bb86a0a93f0861 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,7 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_file = file_load($result->id(), TRUE); + $loaded_file = File::load($result->id()); $this->assertTrue($loaded_file, 'File can be loaded from the database.'); $this->assertFileUnchanged($result, $loaded_file); } @@ -66,14 +68,14 @@ 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)); + $this->assertFileUnchanged($result, File::load($result->id())); // The target file should not have been altered. - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $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); + $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 +104,7 @@ function testExistingReplace() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_result = file_load($result->id(), TRUE); + $loaded_result = File::load($result->id()); $this->assertFileUnchanged($result, $loaded_result); // Check that target was re-used. $this->assertSameFile($target, $loaded_result); @@ -129,7 +131,7 @@ 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)); + $this->assertFileUnchanged($source, File::load($source->id())); } /** @@ -156,7 +158,7 @@ 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)); + $this->assertFileUnchanged($source, File::load($source->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 24d8fb5a1233973eeeeb73384bad06c78077493f..4ca49ad8970ff1d3a3f670fc3f1f261af311bcaf 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,7 @@ 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)); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -57,7 +59,7 @@ 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)); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -82,10 +84,10 @@ function testExistingRename() { // Ensure that the existing file wasn't overwritten. $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)); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -112,7 +114,7 @@ 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)); + $this->assertFileUnchanged($result, File::load($result->id())); } /** @@ -131,6 +133,6 @@ function testExistingError() { $this->assertFileHooksCalled(array()); // Ensure that the existing file wasn't overwritten. - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $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 254917747c66078d91e426dbd06134cabb2f39e5..97d4882e6ca11868b818fc98b8b50485b1c294cf 100644 --- a/core/modules/file/src/Tests/SaveTest.php +++ b/core/modules/file/src/Tests/SaveTest.php @@ -36,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 +53,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 155a67afadb10b894a9a38d0c20deb61a43b246f..baeb443bc2ec286b2aba807e218f1aa526a9916e 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. * @@ -81,7 +83,7 @@ protected 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.'); @@ -100,13 +102,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/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index 5501d8024690261899e735ca847c2ba847779b0b..194c016ce614455b103594b907bc6f7bb97333a7 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -11,6 +11,7 @@ use Drupal\image\Entity\ImageStyle; use Drupal\image\ImageStyleInterface; use Drupal\node\Entity\Node; +use Drupal\file\Entity\File; /** * Tests creation, deletion, and editing of image styles and effects. @@ -302,7 +303,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); @@ -436,7 +437,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/migrate_drupal/src/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php index a2989d4e795d83d3c4c0c2a0a49340040c437ed3..0ec3b7889f7cd81efddd3d091776c03b8ab816b1 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -12,6 +12,7 @@ use Drupal\migrate\Tests\MigrateDumpAlterInterface; use Drupal\Core\Database\Database; use Drupal\simpletest\TestBase; +use Drupal\file\Entity\File; /** * file migration. @@ -62,7 +63,7 @@ protected function setUp() { */ public function testFiles() { /** @var \Drupal\file\FileInterface $file */ - $file = entity_load('file', 1); + $file = File::load(1); $this->assertIdentical('Image1.png', $file->getFilename()); $this->assertIdentical('39325', $file->getSize()); $this->assertIdentical('public://image-1.png', $file->getFileUri()); @@ -96,11 +97,11 @@ public function testFiles() { $executable = new MigrateExecutable($migration, $this); $executable->import(); - $file = entity_load('file', 2); + $file = File::load(2); $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri()); // Ensure that a temporary file has been migrated. - $file = entity_load('file', 6); + $file = File::load(6); $this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri()); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php index b3d15d792485976a563ed619b63585903a269c96..969176cd95075ce4059138822c516a190771ab7a 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\d6\MigrateDrupal6TestBase; +use Drupal\file\Entity\File; /** * User pictures migration. @@ -56,7 +57,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); + $files = File::loadMultiple($file_ids); /** @var \Drupal\file\FileInterface $file */ $file = array_shift($files); $this->assertIdentical('image-test.jpg', $file->getFilename()); diff --git a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php index ead4c2b1b93d19cafff7e81114fbaf788e961bd7..4883d913b75556b21a056ef34b8c9739907cd5f6 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. @@ -68,8 +69,7 @@ protected function setUp() { $node_storage->resetCache(array($nid)); $this->node = $node_storage->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/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php index c5b482adda092cceef86257cee3a6a403db48786..a36a0a8c12bdad351071116f0531e2e63dcd1107 100644 --- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php @@ -10,6 +10,7 @@ use Drupal\image\Entity\ImageStyle; use Drupal\image\Tests\ImageFieldTestBase; use Drupal\node\Entity\Node; +use Drupal\file\Entity\File; /** * Tests the RDFa markup of imagefields. @@ -69,7 +70,7 @@ protected function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article', $this->randomMachineName()); $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/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index b7d996febbd9f70dea71b52141a0c2e85b8fe73c..2885d471b06730f07f209aad376c511e55126d0a 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -17,6 +17,7 @@ use Drupal\node\Entity\Node; use Drupal\taxonomy\Entity\Vocabulary; use Drupal\user\Entity\User; +use Drupal\file\Entity\File; /** * Tests the invocation of hooks when creating, inserting, loading, updating or @@ -257,7 +258,7 @@ public function testFileHooks() { )); $GLOBALS['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/taxonomy/src/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php index fba0f1519c6f01a847e97248f027f13aaedfe28b..550c5f53702e5d8d238c8e0b97d2c0d329c815b7 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php @@ -8,6 +8,7 @@ namespace Drupal\taxonomy\Tests; use Drupal\user\RoleInterface; +use Drupal\file\Entity\File; /** * Tests access checks of private image fields. @@ -86,7 +87,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 efadce57885567aab4917f51d1ebdfe7e3554d83..4f046ab544b4b68964255e3ed3c62059469ad2bd 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. @@ -75,7 +76,7 @@ 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.'); + $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.'); @@ -133,6 +134,6 @@ function saveUserPicture($image) { $user_storage = $this->container->get('entity.manager')->getStorage('user'); $user_storage->resetCache(array($this->webUser->id())); $account = $user_storage->load($this->webUser->id()); - return file_load($account->user_picture->target_id, TRUE); + return File::load($account->user_picture->target_id); } }