Issue #2723593 by alexpott, Jo Fitzgerald, daffie, JacobSanford, rajeshwari10, chishah92, Saviktor, marvin_B8, valthebald, Mile23, Berdir: Properly deprecate entity_load() and friends

8.7.x
Nathaniel Catchpole 2019-02-05 12:08:32 +00:00
parent 21b62c60ab
commit a3a1663bfc
21 changed files with 136 additions and 66 deletions

View File

@ -71,22 +71,13 @@ function entity_get_bundles($entity_type = NULL) {
* @return \Drupal\Core\Entity\EntityInterface|null * @return \Drupal\Core\Entity\EntityInterface|null
* The entity object, or NULL if there is no entity with the given ID. * 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 * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use the
* The method overriding Entity::load() for the entity type, e.g. * entity type storage's load() method.
* \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
* *
* @see \Drupal\Core\Entity\EntityInterface::load() * @see https://www.drupal.org/node/2266845
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
* @see \Drupal\Core\Entity\EntityStorageInterface::load()
* @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage
* @see \Drupal\Core\Entity\Query\QueryInterface
*/ */
function entity_load($entity_type, $id, $reset = FALSE) { 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); $controller = \Drupal::entityManager()->getStorage($entity_type);
if ($reset) { if ($reset) {
$controller->resetCache([$id]); $controller->resetCache([$id]);

View File

@ -31,7 +31,7 @@ class ConfigEntityStatusUITest extends BrowserTestBase {
]; ];
$this->drupalPostForm('admin/structure/config_test/add', $edit, 'Save'); $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 an entity.
$disable_url = $entity->toUrl('disable'); $disable_url = $entity->toUrl('disable');

View File

@ -316,7 +316,8 @@ class ConfigEntityTest extends BrowserTestBase {
$this->assertLinkByHref('admin/structure/config_test/manage/0'); $this->assertLinkByHref('admin/structure/config_test/manage/0');
$this->assertLinkByHref('admin/structure/config_test/manage/0/delete'); $this->assertLinkByHref('admin/structure/config_test/manage/0/delete');
$this->drupalPostForm('admin/structure/config_test/manage/0/delete', [], '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 // 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 // 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']; $edit += ['size_value' => 'medium'];
$this->drupalPostForm(NULL, $edit, 'Save'); $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'), 'custom');
$this->assertEqual($entity->get('size_value'), 'medium'); $this->assertEqual($entity->get('size_value'), 'medium');
} }

View File

@ -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_other_module_config_test][enable]' => TRUE], t('Install'));
$this->drupalPostForm('admin/modules', ['modules[config_install_dependency_test][enable]' => TRUE], t('Install')); $this->drupalPostForm('admin/modules', ['modules[config_install_dependency_test][enable]' => TRUE], t('Install'));
$this->rebuildContainer(); $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.');
} }
/** /**

View File

@ -26,7 +26,7 @@ class ConfigOtherModuleTest extends BrowserTestBase {
// Install the module that provides the entity type. This installs the // Install the module that provides the entity type. This installs the
// default configuration. // default configuration.
$this->installModule('config_test'); $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 // Uninstall the module that provides the entity type. This will remove the
// default configuration. // default configuration.
@ -37,7 +37,7 @@ class ConfigOtherModuleTest extends BrowserTestBase {
// Install the module that provides the entity type again. This installs the // Install the module that provides the entity type again. This installs the
// default configuration. // default configuration.
$this->installModule('config_test'); $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."); $this->assertTrue($other_module_config_entity, "Default configuration has been recreated.");
// Update the default configuration to test that the changes are preserved // 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. // Uninstall the module that provides the default configuration.
$this->uninstallModule('config_other_module_config_test'); $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. // 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 // Re-enable module to test that pre-existing optional configuration does
// not throw an error. // not throw an error.
@ -59,17 +59,16 @@ class ConfigOtherModuleTest extends BrowserTestBase {
// Ensure that optional configuration with unmet dependencies is only // Ensure that optional configuration with unmet dependencies is only
// installed once all the dependencies are met. // 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($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(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->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->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->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->installModule('config_install_dependency_test'); $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 // The following configuration entity's dependencies are now met. It is
// indirectly dependent on the config_install_dependency_test module because // indirectly dependent on the config_install_dependency_test module because
// it has a dependency on the config_test.dynamic.dependency_for_unmet2 // it has a dependency on the config_test.dynamic.dependency_for_unmet2
// configuration provided by that module and, therefore, should be created. // 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 // The following configuration entity's dependencies are now met even though
// it has no direct dependency on the module. It is indirectly dependent on // 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 // the config_test.dynamic.other_module_test_unmet configuration that is
// dependent on the config_install_dependency_test module and, therefore, // dependent on the config_install_dependency_test module and, therefore,
// should be created. // 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.'); $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.');
$entity->delete(); $entity->delete();
// Install another module to ensure the configuration just deleted is not // Install another module to ensure the configuration just deleted is not
// recreated. // recreated.
$this->installModule('config'); $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() { public function testInstallConfigEntityModuleFirst() {
$this->installModule('config_test'); $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->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() { public function testUninstall() {
$this->installModule('views'); $this->installModule('views');
$storage = $this->container->get('entity_type.manager')->getStorage('view'); $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.');
$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->installModule('node'); $this->installModule('node');
$storage->resetCache(['frontpage']); $this->assertTrue($this->getStorage('view')->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.');
$this->assertTrue($storage->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.');
$this->uninstallModule('node'); $this->uninstallModule('node');
$storage = $this->container->get('entity_type.manager')->getStorage('view'); $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.');
$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.');
} }
/** /**
@ -137,4 +131,18 @@ class ConfigOtherModuleTest extends BrowserTestBase {
$this->container = \Drupal::getContainer(); $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);
}
} }

View File

@ -246,7 +246,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
*/ */
protected function saveEntity(EntityInterface $entity) { protected function saveEntity(EntityInterface $entity) {
$entity->save(); $entity->save();
$entity = entity_test_mul_load($entity->id(), TRUE); $entity = \Drupal::entityTypeManager()->getStorage('entity_test_mul')->loadUnchanged($entity->id());
return $entity; return $entity;
} }

View File

@ -102,13 +102,13 @@ function file_load_multiple(array $fids = NULL, $reset = FALSE) {
* @return \Drupal\file\FileInterface|null * @return \Drupal\file\FileInterface|null
* A file entity or NULL if the file was not found. * A file entity or NULL if the file was not found.
* *
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0. * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* Use \Drupal\file\Entity\File::load(). * \Drupal\file\Entity\File::load().
* *
* @see hook_ENTITY_TYPE_load() * @see https://www.drupal.org/node/2266845
* @see file_load_multiple()
*/ */
function file_load($fid, $reset = FALSE) { 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) { if ($reset) {
\Drupal::entityManager()->getStorage('file')->resetCache([$fid]); \Drupal::entityManager()->getStorage('file')->resetCache([$fid]);
} }

View File

@ -2,6 +2,7 @@
namespace Drupal\Tests\file\Kernel; namespace Drupal\Tests\file\Kernel;
use Drupal\file\FileInterface;
use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\file\Entity\File; 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_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() { public function testEntityLegacyCode() {
file_put_contents('public://example.txt', $this->randomMachineName()); file_put_contents('public://example.txt', $this->randomMachineName());
@ -56,6 +58,9 @@ class FileLegacyTest extends FieldKernelTestBase {
$this->assertCount(1, file_load_multiple()); $this->assertCount(1, file_load_multiple());
File::create(['uri' => 'public://example.txt'])->save(); File::create(['uri' => 'public://example.txt'])->save();
$this->assertCount(2, file_load_multiple()); $this->assertCount(2, file_load_multiple());
$this->assertNull(file_load(300));
$this->assertInstanceOf(FileInterface::class, file_load(1));
} }
} }

View File

@ -332,10 +332,13 @@ function node_type_get_description(NodeTypeInterface $node_type) {
* @return \Drupal\node\NodeTypeInterface * @return \Drupal\node\NodeTypeInterface
* A node type object or NULL if $name does not exist. * A node type object or NULL if $name does not exist.
* *
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0. * @deprecated iin Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* Use \Drupal\node\Entity\NodeType::load(). * \Drupal\node\Entity\NodeType::load().
*
* @see https://www.drupal.org/node/2266845
*/ */
function node_type_load($name) { 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); return NodeType::load($name);
} }
@ -468,10 +471,13 @@ function node_load_multiple(array $nids = NULL, $reset = FALSE) {
* @return \Drupal\node\NodeInterface|null * @return \Drupal\node\NodeInterface|null
* A fully-populated node entity, or NULL if the node is not found. * 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. * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* Use \Drupal\node\Entity\Node::load(). * \Drupal\node\Entity\Node::load().
*
* @see https://www.drupal.org/node/2266845
*/ */
function node_load($nid = NULL, $reset = FALSE) { 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) { if ($reset) {
\Drupal::entityManager()->getStorage('node')->resetCache([$nid]); \Drupal::entityManager()->getStorage('node')->resetCache([$nid]);
} }

View File

@ -5,6 +5,8 @@ namespace Drupal\Tests\node\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\node\NodeTypeInterface;
/** /**
* Tests legacy user functionality. * 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_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() { public function testEntityLegacyCode() {
$this->assertCount(0, node_load_multiple()); $this->assertCount(0, node_load_multiple());
@ -52,6 +56,11 @@ class NodeLegacyTest extends EntityKernelTestBase {
'title' => $this->randomMachineName(), 'title' => $this->randomMachineName(),
])->save(); ])->save();
$this->assertCount(2, node_load_multiple()); $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'));
} }
} }

View File

@ -361,8 +361,14 @@ function entity_test_form_node_form_alter(&$form, FormStateInterface $form_state
* *
* @return \Drupal\entity_test\Entity\EntityTest * @return \Drupal\entity_test\Entity\EntityTest
* The loaded entity object, or NULL if the entity cannot be loaded. * 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) { 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'); $storage = \Drupal::entityTypeManager()->getStorage('entity_test');
if ($reset) { if ($reset) {
$storage->resetCache([$id]); $storage->resetCache([$id]);
@ -380,8 +386,14 @@ function entity_test_load($id, $reset = FALSE) {
* *
* @return \Drupal\entity_test\Entity\EntityTestRev * @return \Drupal\entity_test\Entity\EntityTestRev
* The loaded entity object, or NULL if the entity cannot be loaded. * 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) { 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'); $storage = \Drupal::entityTypeManager()->getStorage('entity_test_rev');
if ($reset) { if ($reset) {
$storage->resetCache([$id]); $storage->resetCache([$id]);
@ -399,8 +411,14 @@ function entity_test_rev_load($id, $reset = FALSE) {
* *
* @return \Drupal\entity_test\Entity\EntityTestMul * @return \Drupal\entity_test\Entity\EntityTestMul
* The loaded entity object, or FALSE if the entity cannot be loaded. * 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) { 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'); $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul');
if ($reset) { if ($reset) {
$storage->resetCache([$id]); $storage->resetCache([$id]);
@ -418,8 +436,14 @@ function entity_test_mul_load($id, $reset = FALSE) {
* *
* @return \Drupal\entity_test\Entity\EntityTestMulRev * @return \Drupal\entity_test\Entity\EntityTestMulRev
* The loaded entity object, or NULL if the entity cannot be loaded. * 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) { 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'); $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev');
if ($reset) { if ($reset) {
$storage->resetCache([$id]); $storage->resetCache([$id]);

View File

@ -399,34 +399,40 @@ function taxonomy_vocabulary_load_multiple(array $vids = NULL) {
/** /**
* Return the taxonomy vocabulary entity matching a vocabulary ID. * 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 * @param int $vid
* The vocabulary's ID. * The vocabulary's ID.
* *
* @return \Drupal\taxonomy\Entity\Vocabulary|null * @return \Drupal\taxonomy\Entity\Vocabulary|null
* The taxonomy vocabulary entity, if exists, NULL otherwise. Results are * The taxonomy vocabulary entity, if exists, NULL otherwise. Results are
* statically cached. * 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) { 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 Vocabulary::load($vid);
} }
/** /**
* Return the taxonomy term entity matching a term ID. * 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 * @param $tid
* A term's ID * A term's ID
* *
* @return \Drupal\taxonomy\Entity\Term|null * @return \Drupal\taxonomy\Entity\Term|null
* A taxonomy term entity, or NULL if the term was not found. Results are * A taxonomy term entity, or NULL if the term was not found. Results are
* statically cached. * 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) { 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)) { if (!is_numeric($tid)) {
return NULL; return NULL;
} }

View File

@ -3,6 +3,8 @@
namespace Drupal\Tests\taxonomy\Kernel; namespace Drupal\Tests\taxonomy\Kernel;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\VocabularyInterface;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; 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_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_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() { public function testEntityLegacyCode() {
$this->assertCount(0, taxonomy_term_load_multiple()); $this->assertCount(0, taxonomy_term_load_multiple());
@ -45,6 +49,11 @@ class TaxonomyLegacyTest extends KernelTestBase {
$this->createTerm($vocab); $this->createTerm($vocab);
$this->assertCount(3, taxonomy_term_load_multiple()); $this->assertCount(3, taxonomy_term_load_multiple());
$this->assertCount(2, taxonomy_vocabulary_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()));
} }
} }

View File

@ -4,6 +4,7 @@ namespace Drupal\Tests\user\Kernel;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
/** /**
* Tests legacy user functionality. * 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_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() { public function testEntityLegacyCode() {
$this->installSchema('system', ['sequences']); $this->installSchema('system', ['sequences']);
@ -38,6 +40,9 @@ class UserLegacyTest extends KernelTestBase {
$this->assertCount(1, user_load_multiple()); $this->assertCount(1, user_load_multiple());
User::create(['name' => 'bar'])->save(); User::create(['name' => 'bar'])->save();
$this->assertCount(2, user_load_multiple()); $this->assertCount(2, user_load_multiple());
$this->assertNull(user_load(300));
$this->assertInstanceOf(UserInterface::class, user_load(1));
} }
} }

View File

@ -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 * A fully-loaded user object upon successful user load, or NULL if the user
* cannot be loaded. * cannot be loaded.
* *
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0. * @deprecated iin Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* Use \Drupal\user\Entity\User::load(). * Drupal\user\Entity\User::load().
* *
* @see \Drupal\user\Entity\User::loadMultiple() * @see https://www.drupal.org/node/2266845
*/ */
function user_load($uid, $reset = FALSE) { 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) { if ($reset) {
\Drupal::entityManager()->getStorage('user')->resetCache([$uid]); \Drupal::entityManager()->getStorage('user')->resetCache([$uid]);
} }

View File

@ -96,9 +96,9 @@ class WorkspaceIntegrationTest extends KernelTestBase {
// - a multi-dimensional array keyed by the workspace ID, then by the entity // - a multi-dimensional array keyed by the workspace ID, then by the entity
// ID and finally by the revision ID. // ID and finally by the revision ID.
// - 'default_revision' indicates the entity revision that should be // - 'default_revision' indicates the entity revision that should be
// returned by entity_load(), non-revision entity queries and non-revision // returned when loading an entity, non-revision entity queries and
// views *in a given workspace*, it does not indicate what is actually // non-revision views *in a given workspace*, it does not indicate what is
// stored in the base and data entity tables. // actually stored in the base and data entity tables.
$test_scenarios = []; $test_scenarios = [];
// The $expected_workspace_association array holds the revision IDs which // The $expected_workspace_association array holds the revision IDs which

View File

@ -35,8 +35,7 @@ class ConfigEntityNormalizeTest extends KernelTestBase {
] + $config->getRawData(); ] + $config->getRawData();
$config->setData($data)->save(); $config->setData($data)->save();
$this->assertNotIdentical($config_entity->toArray(), $config->getRawData(), 'Stored config entity is not is equivalent to config schema.'); $this->assertNotIdentical($config_entity->toArray(), $config->getRawData(), 'Stored config entity is not is equivalent to config schema.');
$config_entity = \Drupal::entityTypeManager()->getStorage('config_test')->load('system');
$config_entity = entity_load('config_test', 'system', TRUE);
$config_entity->save(); $config_entity->save();
$config = $this->config('config_test.dynamic.system'); $config = $this->config('config_test.dynamic.system');

View File

@ -35,7 +35,7 @@ class ConfigEntityStatusTest extends KernelTestBase {
$entity->enable()->save(); $entity->enable()->save();
$this->assertTrue($entity->status(), 'Entity is enabled after enabling.'); $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.'); $this->assertTrue($entity->status(), 'Status is enabled after reload.');
} }

View File

@ -47,7 +47,7 @@ class ConfigEntityStorageTest extends KernelTestBase {
} }
// Ensure that the config entity was not corrupted. // 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); $this->assertIdentical($entity->toArray(), $original_properties);
} }

View File

@ -2,6 +2,7 @@
namespace Drupal\KernelTests\Core\Entity; namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestMul; use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\KernelTests\KernelTestBase; 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_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() { public function testEntityLegacyCode() {
$this->assertCount(0, entity_load_multiple('entity_test')); $this->assertCount(0, entity_load_multiple('entity_test'));
@ -44,6 +46,9 @@ class EntityLegacyTest extends KernelTestBase {
EntityTestMul::create(['name' => 'published entity'])->save(); EntityTestMul::create(['name' => 'published entity'])->save();
$this->assertCount(2, entity_load_multiple('entity_test')); $this->assertCount(2, entity_load_multiple('entity_test'));
$this->assertCount(1, entity_load_multiple('entity_test_mul')); $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));
} }
} }

View File

@ -169,6 +169,7 @@ class EntityRevisionTranslationTest extends EntityKernelTestBase {
// All revisionable entity variations have to have the same results. // All revisionable entity variations have to have the same results.
foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) { foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) {
$this->installEntitySchema($entity_type); $this->installEntitySchema($entity_type);
$storage = \Drupal::entityTypeManager()->getStorage($entity_type);
$entity = entity_create($entity_type, [ $entity = entity_create($entity_type, [
'name' => 'foo', 'name' => 'foo',
@ -178,12 +179,12 @@ class EntityRevisionTranslationTest extends EntityKernelTestBase {
$entity->save(); $entity->save();
$entity_id = $entity->id(); $entity_id = $entity->id();
$entity_rev_id = $entity->getRevisionId(); $entity_rev_id = $entity->getRevisionId();
$entity = entity_load($entity_type, $entity_id, TRUE); $entity = $storage->loadUnchanged($entity_id);
$entity->setNewRevision(TRUE); $entity->setNewRevision(TRUE);
$entity->setNewRevision(FALSE); $entity->setNewRevision(FALSE);
$entity->save(); $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.'); $this->assertEquals($entity_rev_id, $entity->getRevisionId(), 'A new entity revision was not created.');
} }