diff --git a/core/includes/entity.inc b/core/includes/entity.inc index a18fdede12b8..0dc442601439 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -71,22 +71,13 @@ function entity_get_bundles($entity_type = NULL) { * @return \Drupal\Core\Entity\EntityInterface|null * The entity object, or NULL if there is no entity with the given ID. * - * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use - * The method overriding Entity::load() for the entity type, e.g. - * \Drupal\node\Entity\Node::load() if the entity type is known. If the - * entity type is variable, use the entity manager service to load the entity - * from the entity storage: - * @code - * \Drupal::entityTypeManager()->getStorage($entity_type)->load($id); - * @endcode + * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use the + * entity type storage's load() method. * - * @see \Drupal\Core\Entity\EntityInterface::load() - * @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage() - * @see \Drupal\Core\Entity\EntityStorageInterface::load() - * @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage - * @see \Drupal\Core\Entity\Query\QueryInterface + * @see https://www.drupal.org/node/2266845 */ function entity_load($entity_type, $id, $reset = FALSE) { + @trigger_error('entity_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage\'s load() method. See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); $controller = \Drupal::entityManager()->getStorage($entity_type); if ($reset) { $controller->resetCache([$id]); diff --git a/core/modules/config/tests/src/Functional/ConfigEntityStatusUITest.php b/core/modules/config/tests/src/Functional/ConfigEntityStatusUITest.php index 3db476bb3e1b..b0fa22f2dec9 100644 --- a/core/modules/config/tests/src/Functional/ConfigEntityStatusUITest.php +++ b/core/modules/config/tests/src/Functional/ConfigEntityStatusUITest.php @@ -31,7 +31,7 @@ class ConfigEntityStatusUITest extends BrowserTestBase { ]; $this->drupalPostForm('admin/structure/config_test/add', $edit, 'Save'); - $entity = entity_load('config_test', $id); + $entity = \Drupal::entityTypeManager()->getStorage('config_test')->load($id); // Disable an entity. $disable_url = $entity->toUrl('disable'); diff --git a/core/modules/config/tests/src/Functional/ConfigEntityTest.php b/core/modules/config/tests/src/Functional/ConfigEntityTest.php index 94b9be764b05..2b72ef511783 100644 --- a/core/modules/config/tests/src/Functional/ConfigEntityTest.php +++ b/core/modules/config/tests/src/Functional/ConfigEntityTest.php @@ -316,7 +316,8 @@ class ConfigEntityTest extends BrowserTestBase { $this->assertLinkByHref('admin/structure/config_test/manage/0'); $this->assertLinkByHref('admin/structure/config_test/manage/0/delete'); $this->drupalPostForm('admin/structure/config_test/manage/0/delete', [], 'Delete'); - $this->assertFalse(entity_load('config_test', '0'), 'Test entity deleted'); + $storage = \Drupal::entityTypeManager()->getStorage('config_test'); + $this->assertNull($storage->load(0), 'Test entity deleted'); // Create a configuration entity with a property that uses AJAX to show // extra form elements. Test this scenario in a non-JS case by using a @@ -343,7 +344,7 @@ class ConfigEntityTest extends BrowserTestBase { $edit += ['size_value' => 'medium']; $this->drupalPostForm(NULL, $edit, 'Save'); - $entity = entity_load('config_test', $id); + $entity = $storage->load($id); $this->assertEqual($entity->get('size'), 'custom'); $this->assertEqual($entity->get('size_value'), 'medium'); } diff --git a/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php b/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php index 5ac93bb8abc1..ab235ed8e50b 100644 --- a/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php +++ b/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php @@ -190,7 +190,7 @@ class ConfigInstallWebTest extends BrowserTestBase { $this->drupalPostForm('admin/modules', ['modules[config_other_module_config_test][enable]' => TRUE], t('Install')); $this->drupalPostForm('admin/modules', ['modules[config_install_dependency_test][enable]' => TRUE], t('Install')); $this->rebuildContainer(); - $this->assertTrue(entity_load('config_test', 'other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.'); + $this->assertTrue(\Drupal::entityTypeManager()->getStorage('config_test')->load('other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.'); } /** diff --git a/core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php b/core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php index e1bc859b2992..4ff2b18f80bc 100644 --- a/core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php +++ b/core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php @@ -26,7 +26,7 @@ class ConfigOtherModuleTest extends BrowserTestBase { // Install the module that provides the entity type. This installs the // default configuration. $this->installModule('config_test'); - $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.'); + $this->assertTrue($this->getStorage()->load('other_module_test'), 'Default configuration has been installed.'); // Uninstall the module that provides the entity type. This will remove the // default configuration. @@ -37,7 +37,7 @@ class ConfigOtherModuleTest extends BrowserTestBase { // Install the module that provides the entity type again. This installs the // default configuration. $this->installModule('config_test'); - $other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE); + $other_module_config_entity = $this->getStorage()->load('other_module_test'); $this->assertTrue($other_module_config_entity, "Default configuration has been recreated."); // Update the default configuration to test that the changes are preserved @@ -47,10 +47,10 @@ class ConfigOtherModuleTest extends BrowserTestBase { // Uninstall the module that provides the default configuration. $this->uninstallModule('config_other_module_config_test'); - $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration for other modules is not removed when the module that provides it is uninstalled.'); + $this->assertTrue($this->getStorage()->load('other_module_test'), 'Default configuration for other modules is not removed when the module that provides it is uninstalled.'); // Default configuration provided by config_test should still exist. - $this->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.'); + $this->assertTrue($this->getStorage()->load('dotted.default'), 'The configuration is not deleted.'); // Re-enable module to test that pre-existing optional configuration does // not throw an error. @@ -59,17 +59,16 @@ class ConfigOtherModuleTest extends BrowserTestBase { // Ensure that optional configuration with unmet dependencies is only // installed once all the dependencies are met. - $this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.'); - $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.'); - $this->installModule('config_test_language'); - $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are not met is not created.'); + $this->assertNull($this->getStorage()->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.'); + $this->assertNull($this->getStorage()->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.'); $this->installModule('config_test_language'); + $this->assertNull($this->getStorage()->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.'); $this->installModule('config_install_dependency_test'); - $this->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.'); + $this->assertTrue($this->getStorage()->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.'); // The following configuration entity's dependencies are now met. It is // indirectly dependent on the config_install_dependency_test module because // it has a dependency on the config_test.dynamic.dependency_for_unmet2 // configuration provided by that module and, therefore, should be created. - $this->assertTrue(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are met is now created.'); + $this->assertTrue($this->getStorage()->load('other_module_test_optional_entity_unmet2'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are met is now created.'); // The following configuration entity's dependencies are now met even though // it has no direct dependency on the module. It is indirectly dependent on @@ -77,14 +76,14 @@ class ConfigOtherModuleTest extends BrowserTestBase { // the config_test.dynamic.other_module_test_unmet configuration that is // dependent on the config_install_dependency_test module and, therefore, // should be created. - $entity = entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE); + $entity = $this->getStorage()->load('other_module_test_optional_entity_unmet'); $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.'); $entity->delete(); // Install another module to ensure the configuration just deleted is not // recreated. $this->installModule('config'); - $this->assertFalse(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not installed when an unrelated module is installed.'); + $this->assertFalse($this->getStorage()->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not installed when an unrelated module is installed.'); } /** @@ -92,10 +91,10 @@ class ConfigOtherModuleTest extends BrowserTestBase { */ public function testInstallConfigEntityModuleFirst() { $this->installModule('config_test'); - $this->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.'); + $this->assertFalse($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test does not exist.'); $this->installModule('config_other_module_config_test'); - $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.'); + $this->assertTrue($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test has been installed.'); } /** @@ -103,16 +102,11 @@ class ConfigOtherModuleTest extends BrowserTestBase { */ public function testUninstall() { $this->installModule('views'); - $storage = $this->container->get('entity_type.manager')->getStorage('view'); - $storage->resetCache(['frontpage']); - $this->assertTrue($storage->load('frontpage') === NULL, 'After installing Views, frontpage view which is dependant on the Node and Views modules does not exist.'); + $this->assertTrue($this->getStorage('view')->load('frontpage') === NULL, 'After installing Views, frontpage view which is dependant on the Node and Views modules does not exist.'); $this->installModule('node'); - $storage->resetCache(['frontpage']); - $this->assertTrue($storage->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.'); + $this->assertTrue($this->getStorage('view')->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.'); $this->uninstallModule('node'); - $storage = $this->container->get('entity_type.manager')->getStorage('view'); - $storage->resetCache(['frontpage']); - $this->assertTrue($storage->load('frontpage') === NULL, 'After uninstalling Node, frontpage view which is dependant on the Node and Views modules does not exist.'); + $this->assertTrue($this->getStorage('view')->load('frontpage') === NULL, 'After uninstalling Node, frontpage view which is dependant on the Node and Views modules does not exist.'); } /** @@ -137,4 +131,18 @@ class ConfigOtherModuleTest extends BrowserTestBase { $this->container = \Drupal::getContainer(); } + /** + * Gets the provided entity type's storage. + * + * @param string $entity_type_id + * (optional) The entity type ID to get a storage for. Defaults to + * 'config_test'. + * + * @return \Drupal\Core\Entity\EntityStorageInterface + * The entity type's storage. + */ + protected function getStorage($entity_type_id = 'config_test') { + return \Drupal::entityTypeManager()->getStorage($entity_type_id); + } + } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php index 5f7c9fd9b8ec..99d93331cace 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php @@ -246,7 +246,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase { */ protected function saveEntity(EntityInterface $entity) { $entity->save(); - $entity = entity_test_mul_load($entity->id(), TRUE); + $entity = \Drupal::entityTypeManager()->getStorage('entity_test_mul')->loadUnchanged($entity->id()); return $entity; } diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 79b8c07a1c7f..d220cabc576e 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -102,13 +102,13 @@ function file_load_multiple(array $fids = NULL, $reset = FALSE) { * @return \Drupal\file\FileInterface|null * A file entity or NULL if the file was not found. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\file\Entity\File::load(). + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\file\Entity\File::load(). * - * @see hook_ENTITY_TYPE_load() - * @see file_load_multiple() + * @see https://www.drupal.org/node/2266845 */ function file_load($fid, $reset = FALSE) { + @trigger_error('file_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); if ($reset) { \Drupal::entityManager()->getStorage('file')->resetCache([$fid]); } diff --git a/core/modules/file/tests/src/Kernel/FileLegacyTest.php b/core/modules/file/tests/src/Kernel/FileLegacyTest.php index 43c11fb40206..842c8500baba 100644 --- a/core/modules/file/tests/src/Kernel/FileLegacyTest.php +++ b/core/modules/file/tests/src/Kernel/FileLegacyTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Kernel; +use Drupal\file\FileInterface; use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\file\Entity\File; @@ -48,6 +49,7 @@ class FileLegacyTest extends FieldKernelTestBase { /** * @expectedDeprecation file_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::loadMultiple(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation file_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::load(). See https://www.drupal.org/node/2266845 */ public function testEntityLegacyCode() { file_put_contents('public://example.txt', $this->randomMachineName()); @@ -56,6 +58,9 @@ class FileLegacyTest extends FieldKernelTestBase { $this->assertCount(1, file_load_multiple()); File::create(['uri' => 'public://example.txt'])->save(); $this->assertCount(2, file_load_multiple()); + + $this->assertNull(file_load(300)); + $this->assertInstanceOf(FileInterface::class, file_load(1)); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 1629d25cd8de..9fdabf32b4ad 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -332,10 +332,13 @@ function node_type_get_description(NodeTypeInterface $node_type) { * @return \Drupal\node\NodeTypeInterface * A node type object or NULL if $name does not exist. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\node\Entity\NodeType::load(). + * @deprecated iin Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\node\Entity\NodeType::load(). + * + * @see https://www.drupal.org/node/2266845 */ function node_type_load($name) { + @trigger_error('node_type_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\NodeType::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); return NodeType::load($name); } @@ -468,10 +471,13 @@ function node_load_multiple(array $nids = NULL, $reset = FALSE) { * @return \Drupal\node\NodeInterface|null * A fully-populated node entity, or NULL if the node is not found. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\node\Entity\Node::load(). + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\node\Entity\Node::load(). + * + * @see https://www.drupal.org/node/2266845 */ function node_load($nid = NULL, $reset = FALSE) { + @trigger_error('node_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\Node::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); if ($reset) { \Drupal::entityManager()->getStorage('node')->resetCache([$nid]); } diff --git a/core/modules/node/tests/src/Kernel/NodeLegacyTest.php b/core/modules/node/tests/src/Kernel/NodeLegacyTest.php index ecd290c1342c..fe25f457e091 100644 --- a/core/modules/node/tests/src/Kernel/NodeLegacyTest.php +++ b/core/modules/node/tests/src/Kernel/NodeLegacyTest.php @@ -5,6 +5,8 @@ namespace Drupal\Tests\node\Kernel; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; +use Drupal\node\NodeInterface; +use Drupal\node\NodeTypeInterface; /** * Tests legacy user functionality. @@ -39,6 +41,8 @@ class NodeLegacyTest extends EntityKernelTestBase { /** * @expectedDeprecation node_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\Node::loadMultiple(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation node_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\Node::load(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation node_type_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\node\Entity\NodeType::load(). See https://www.drupal.org/node/2266845 */ public function testEntityLegacyCode() { $this->assertCount(0, node_load_multiple()); @@ -52,6 +56,11 @@ class NodeLegacyTest extends EntityKernelTestBase { 'title' => $this->randomMachineName(), ])->save(); $this->assertCount(2, node_load_multiple()); + + $this->assertNull(node_load(30)); + $this->assertInstanceOf(NodeInterface::class, node_load(1)); + $this->assertNull(node_type_load('a_node_type_does_not_exist')); + $this->assertInstanceOf(NodeTypeInterface::class, node_type_load('page')); } } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 66a42e2931c6..3e63e736f2d1 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -361,8 +361,14 @@ function entity_test_form_node_form_alter(&$form, FormStateInterface $form_state * * @return \Drupal\entity_test\Entity\EntityTest * The loaded entity object, or NULL if the entity cannot be loaded. + * + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal::entityTypeManager()->getStorage('entity_test')->load(). + * + * @see https://www.drupal.org/node/2266845 */ function entity_test_load($id, $reset = FALSE) { + @trigger_error('entity_test_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); $storage = \Drupal::entityTypeManager()->getStorage('entity_test'); if ($reset) { $storage->resetCache([$id]); @@ -380,8 +386,14 @@ function entity_test_load($id, $reset = FALSE) { * * @return \Drupal\entity_test\Entity\EntityTestRev * The loaded entity object, or NULL if the entity cannot be loaded. + * + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal::entityTypeManager()->getStorage('entity_test_rev')->load(). + * + * @see https://www.drupal.org/node/2266845 */ function entity_test_rev_load($id, $reset = FALSE) { + @trigger_error('entity_test_rev_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test_rev\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); $storage = \Drupal::entityTypeManager()->getStorage('entity_test_rev'); if ($reset) { $storage->resetCache([$id]); @@ -399,8 +411,14 @@ function entity_test_rev_load($id, $reset = FALSE) { * * @return \Drupal\entity_test\Entity\EntityTestMul * The loaded entity object, or FALSE if the entity cannot be loaded. + * + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal::entityTypeManager()->getStorage('entity_test_mul')->load(). + * + * @see https://www.drupal.org/node/2266845 */ function entity_test_mul_load($id, $reset = FALSE) { + @trigger_error('entity_test_mul_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test_mul\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul'); if ($reset) { $storage->resetCache([$id]); @@ -418,8 +436,14 @@ function entity_test_mul_load($id, $reset = FALSE) { * * @return \Drupal\entity_test\Entity\EntityTestMulRev * The loaded entity object, or NULL if the entity cannot be loaded. + * + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal::entityTypeManager()->getStorage('entity_test_mulrev_load')->load(). + * + * @see https://www.drupal.org/node/2266845 */ function entity_test_mulrev_load($id, $reset = FALSE) { + @trigger_error('entity_test_mulrev_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test_mulrev\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev'); if ($reset) { $storage->resetCache([$id]); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 8b648b796a8f..652ba32d0790 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -399,34 +399,40 @@ function taxonomy_vocabulary_load_multiple(array $vids = NULL) { /** * Return the taxonomy vocabulary entity matching a vocabulary ID. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\taxonomy\Entity\Vocabulary::load(). - * * @param int $vid * The vocabulary's ID. * * @return \Drupal\taxonomy\Entity\Vocabulary|null * The taxonomy vocabulary entity, if exists, NULL otherwise. Results are * statically cached. + * + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\taxonomy\Entity\Vocabulary::load(). + * + * @see https://www.drupal.org/node/2266845 */ function taxonomy_vocabulary_load($vid) { + @trigger_error('taxonomy_vocabulary_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Vocabulary::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); return Vocabulary::load($vid); } /** * Return the taxonomy term entity matching a term ID. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\taxonomy\Entity\Term::load(). - * * @param $tid * A term's ID * * @return \Drupal\taxonomy\Entity\Term|null * A taxonomy term entity, or NULL if the term was not found. Results are * statically cached. + * + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * Drupal\taxonomy\Entity\Term::load(). + * + * @see https://www.drupal.org/node/2266845 */ function taxonomy_term_load($tid) { + @trigger_error('taxonomy_term_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Term::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); if (!is_numeric($tid)) { return NULL; } diff --git a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php index 1971b4a1dff9..429e6fdafd35 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php @@ -3,6 +3,8 @@ namespace Drupal\Tests\taxonomy\Kernel; use Drupal\KernelTests\KernelTestBase; +use Drupal\taxonomy\TermInterface; +use Drupal\taxonomy\VocabularyInterface; use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; /** @@ -33,6 +35,8 @@ class TaxonomyLegacyTest extends KernelTestBase { /** * @expectedDeprecation taxonomy_term_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Term::loadMultiple(). See https://www.drupal.org/node/2266845 * @expectedDeprecation taxonomy_vocabulary_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Vocabulary::loadMultiple(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation taxonomy_term_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Term::load(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation taxonomy_vocabulary_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\taxonomy\Entity\Vocabulary::load(). See https://www.drupal.org/node/2266845 */ public function testEntityLegacyCode() { $this->assertCount(0, taxonomy_term_load_multiple()); @@ -45,6 +49,11 @@ class TaxonomyLegacyTest extends KernelTestBase { $this->createTerm($vocab); $this->assertCount(3, taxonomy_term_load_multiple()); $this->assertCount(2, taxonomy_vocabulary_load_multiple()); + + $this->assertNull(taxonomy_term_load(3000)); + $this->assertInstanceOf(TermInterface::class, taxonomy_term_load(1)); + $this->assertNull(taxonomy_vocabulary_load('not_a_vocab')); + $this->assertInstanceOf(VocabularyInterface::class, taxonomy_vocabulary_load($vocab->id())); } } diff --git a/core/modules/user/tests/src/Kernel/UserLegacyTest.php b/core/modules/user/tests/src/Kernel/UserLegacyTest.php index 48d48afda232..7decba06f8c3 100644 --- a/core/modules/user/tests/src/Kernel/UserLegacyTest.php +++ b/core/modules/user/tests/src/Kernel/UserLegacyTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\user\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\user\Entity\User; +use Drupal\user\UserInterface; /** * Tests legacy user functionality. @@ -30,6 +31,7 @@ class UserLegacyTest extends KernelTestBase { /** * @expectedDeprecation user_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\user\Entity\User::loadMultiple(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation user_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\user\Entity\User::load(). See https://www.drupal.org/node/2266845 */ public function testEntityLegacyCode() { $this->installSchema('system', ['sequences']); @@ -38,6 +40,9 @@ class UserLegacyTest extends KernelTestBase { $this->assertCount(1, user_load_multiple()); User::create(['name' => 'bar'])->save(); $this->assertCount(2, user_load_multiple()); + + $this->assertNull(user_load(300)); + $this->assertInstanceOf(UserInterface::class, user_load(1)); } } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 3d781fb32005..f46d61e0cbb0 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -226,12 +226,13 @@ function user_load_multiple(array $uids = NULL, $reset = FALSE) { * A fully-loaded user object upon successful user load, or NULL if the user * cannot be loaded. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\user\Entity\User::load(). + * @deprecated iin Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * Drupal\user\Entity\User::load(). * - * @see \Drupal\user\Entity\User::loadMultiple() + * @see https://www.drupal.org/node/2266845 */ function user_load($uid, $reset = FALSE) { + @trigger_error('user_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\user\Entity\User::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); if ($reset) { \Drupal::entityManager()->getStorage('user')->resetCache([$uid]); } diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php index 225370fb8ac9..1252a672b36d 100644 --- a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php @@ -96,9 +96,9 @@ class WorkspaceIntegrationTest extends KernelTestBase { // - a multi-dimensional array keyed by the workspace ID, then by the entity // ID and finally by the revision ID. // - 'default_revision' indicates the entity revision that should be - // returned by entity_load(), non-revision entity queries and non-revision - // views *in a given workspace*, it does not indicate what is actually - // stored in the base and data entity tables. + // returned when loading an entity, non-revision entity queries and + // non-revision views *in a given workspace*, it does not indicate what is + // actually stored in the base and data entity tables. $test_scenarios = []; // The $expected_workspace_association array holds the revision IDs which diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityNormalizeTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityNormalizeTest.php index 1b468b0670fa..93b6d8929b82 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityNormalizeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityNormalizeTest.php @@ -35,8 +35,7 @@ class ConfigEntityNormalizeTest extends KernelTestBase { ] + $config->getRawData(); $config->setData($data)->save(); $this->assertNotIdentical($config_entity->toArray(), $config->getRawData(), 'Stored config entity is not is equivalent to config schema.'); - - $config_entity = entity_load('config_test', 'system', TRUE); + $config_entity = \Drupal::entityTypeManager()->getStorage('config_test')->load('system'); $config_entity->save(); $config = $this->config('config_test.dynamic.system'); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php index 20ceef405153..4f6d51c10cc4 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStatusTest.php @@ -35,7 +35,7 @@ class ConfigEntityStatusTest extends KernelTestBase { $entity->enable()->save(); $this->assertTrue($entity->status(), 'Entity is enabled after enabling.'); - $entity = entity_load('config_test', $entity->id()); + $entity = \Drupal::entityTypeManager()->getStorage('config_test')->load($entity->id()); $this->assertTrue($entity->status(), 'Status is enabled after reload.'); } diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php index ce9a928d53a3..a8a377db746d 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php @@ -47,7 +47,7 @@ class ConfigEntityStorageTest extends KernelTestBase { } // Ensure that the config entity was not corrupted. - $entity = entity_load('config_test', $entity->id(), TRUE); + $entity = $storage->loadUnchanged($entity->id()); $this->assertIdentical($entity->toArray(), $original_properties); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php index 51721a73acf7..ff13f6c2b24e 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Core\Entity\EntityInterface; use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTestMul; use Drupal\KernelTests\KernelTestBase; @@ -31,6 +32,7 @@ class EntityLegacyTest extends KernelTestBase { /** * @expectedDeprecation entity_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage's loadMultiple() method. See https://www.drupal.org/node/2266845 + * @expectedDeprecation entity_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage's load() method. See https://www.drupal.org/node/2266845 */ public function testEntityLegacyCode() { $this->assertCount(0, entity_load_multiple('entity_test')); @@ -44,6 +46,9 @@ class EntityLegacyTest extends KernelTestBase { EntityTestMul::create(['name' => 'published entity'])->save(); $this->assertCount(2, entity_load_multiple('entity_test')); $this->assertCount(1, entity_load_multiple('entity_test_mul')); + + $this->assertNull(entity_load('entity_test', 100)); + $this->assertInstanceOf(EntityInterface::class, entity_load('entity_test', 1)); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php index 34969ebd4d16..1d3f1b420d85 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php @@ -169,6 +169,7 @@ class EntityRevisionTranslationTest extends EntityKernelTestBase { // All revisionable entity variations have to have the same results. foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) { $this->installEntitySchema($entity_type); + $storage = \Drupal::entityTypeManager()->getStorage($entity_type); $entity = entity_create($entity_type, [ 'name' => 'foo', @@ -178,12 +179,12 @@ class EntityRevisionTranslationTest extends EntityKernelTestBase { $entity->save(); $entity_id = $entity->id(); $entity_rev_id = $entity->getRevisionId(); - $entity = entity_load($entity_type, $entity_id, TRUE); + $entity = $storage->loadUnchanged($entity_id); $entity->setNewRevision(TRUE); $entity->setNewRevision(FALSE); $entity->save(); - $entity = entity_load($entity_type, $entity_id, TRUE); + $entity = $storage->loadUnchanged($entity_id); $this->assertEquals($entity_rev_id, $entity->getRevisionId(), 'A new entity revision was not created.'); }