Commit a3a1663b authored by catch's avatar catch

Issue #2723593 by alexpott, Jo Fitzgerald, daffie, JacobSanford, rajeshwari10,...

Issue #2723593 by alexpott, Jo Fitzgerald, daffie, JacobSanford, rajeshwari10, chishah92, Saviktor, marvin_B8, valthebald, Mile23, Berdir: Properly deprecate entity_load() and friends
parent 21b62c60
......@@ -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]);
......
......@@ -31,7 +31,7 @@ public function testCRUD() {
];
$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');
......
......@@ -316,7 +316,8 @@ public function testCRUDUI() {
$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 @@ public function testCRUDUI() {
$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');
}
......
......@@ -190,7 +190,7 @@ public function testUnmetDependenciesInstall() {
$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.');
}
/**
......
......@@ -26,7 +26,7 @@ public function testInstallOtherModuleFirst() {
// 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 @@ public function testInstallOtherModuleFirst() {
// 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 @@ public function testInstallOtherModuleFirst() {
// 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 @@ public function testInstallOtherModuleFirst() {
// 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 @@ public function testInstallOtherModuleFirst() {
// 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 @@ public function testInstallOtherModuleFirst() {
*/
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 @@ public function testInstallConfigEntityModuleFirst() {
*/
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 @@ protected function uninstallModule($module) {
$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);
}
}
......@@ -246,7 +246,7 @@ public function testImageFieldSync() {
*/
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;
}
......
......@@ -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]);
}
......
......@@ -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 @@ public function testFileUrlDeprecation() {
/**
* @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 @@ public function testEntityLegacyCode() {
$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));
}
}
......@@ -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]);
}
......
......@@ -5,6 +5,8 @@
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 @@ protected function setUp() {
/**
* @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 @@ public function testEntityLegacyCode() {
'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'));
}
}
......@@ -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]);
......
......@@ -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;
}
......
......@@ -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 @@ protected function setUp() {
/**
* @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 @@ public function testEntityLegacyCode() {
$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()));
}
}
......@@ -4,6 +4,7 @@
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
/**
* Tests legacy user functionality.
......@@ -30,6 +31,7 @@ protected function setUp() {
/**
* @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 @@ public function testEntityLegacyCode() {
$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));
}
}
......@@ -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]);
}
......
......@@ -96,9 +96,9 @@ public function testWorkspaces() {
// - 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
......
......@@ -35,8 +35,7 @@ public function testNormalize() {
] + $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');
......
......@@ -35,7 +35,7 @@ public function testCRUD() {
$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.');
}
......
......@@ -47,7 +47,7 @@ public function testUUIDConflict() {
}
// 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);
}
......
......@@ -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 @@ protected function setUp() {
/**
* @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 @@ public function testEntityLegacyCode() {
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));
}
}
......@@ -169,6 +169,7 @@ public function testSetNewRevision() {
// 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 @@ public function testSetNewRevision() {
$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.');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment