Commit 447cdb78 authored by catch's avatar catch

Issue #3028657 by alexpott, Berdir: Properly deprecate entity_load_multiple()

parent 389fbbff
......@@ -179,22 +179,13 @@ function entity_revision_delete($entity_type, $revision_id) {
* @return array
* An array of entity objects indexed by their IDs.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
* The method overriding Entity::loadMultiple() for the entity type, e.g.
* \Drupal\node\Entity\Node::loadMultiple() 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)->loadMultiple($id);
* @endcode
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
* entity type storage's loadMultiple() method.
*
* @see \Drupal\Core\Entity\EntityInterface::loadMultiple()
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
* @see \Drupal\Core\Entity\EntityStorageInterface::loadMultiple()
* @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage
* @see \Drupal\Core\Entity\Query\QueryInterface
* @see https://www.drupal.org/node/2266845
*/
function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
@trigger_error('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', E_USER_DEPRECATED);
$controller = \Drupal::entityManager()->getStorage($entity_type);
if ($reset) {
$controller->resetCache($ids);
......
......@@ -523,7 +523,7 @@ function editor_file_download($uri) {
$referencing_entity_is_accessible = FALSE;
$references = empty($usage_list['editor']) ? [] : $usage_list['editor'];
foreach ($references as $entity_type => $entity_ids_usage_count) {
$referencing_entities = entity_load_multiple($entity_type, array_keys($entity_ids_usage_count));
$referencing_entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple(array_keys($entity_ids_usage_count));
/** @var \Drupal\Core\Entity\EntityInterface $referencing_entity */
foreach ($referencing_entities as $referencing_entity) {
if ($referencing_entity->access('view', NULL, TRUE)->isAllowed()) {
......
......@@ -77,15 +77,13 @@ function file_field_widget_info_alter(array &$info) {
* @return array
* An array of file entities, indexed by fid.
*
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\file\Entity\File::loadMultiple().
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* \Drupal\file\Entity\File::loadMultiple().
*
* @see hook_ENTITY_TYPE_load()
* @see file_load()
* @see entity_load()
* @see \Drupal\Core\Entity\Query\EntityQueryInterface
* @see https://www.drupal.org/node/2266845
*/
function file_load_multiple(array $fids = NULL, $reset = FALSE) {
@trigger_error('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', E_USER_DEPRECATED);
if ($reset) {
\Drupal::entityManager()->getStorage('file')->resetCache($fids);
}
......
......@@ -46,4 +46,16 @@ public function testFileUrlDeprecation() {
$this->assertEquals($file->createFileUrl(FALSE), $file->url());
}
/**
* @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
*/
public function testEntityLegacyCode() {
file_put_contents('public://example.txt', $this->randomMachineName());
$this->assertCount(0, file_load_multiple());
File::create(['uri' => 'public://example.txt'])->save();
$this->assertCount(1, file_load_multiple());
File::create(['uri' => 'public://example.txt'])->save();
$this->assertCount(2, file_load_multiple());
}
}
......@@ -443,13 +443,13 @@ function node_type_update_nodes($old_id, $new_id) {
* @return \Drupal\node\NodeInterface[]
* An array of node entities indexed by nid.
*
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\node\Entity\Node::loadMultiple().
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* \Drupal\node\Entity\Node::loadMultiple().
*
* @see entity_load_multiple()
* @see \Drupal\Core\Entity\Query\EntityQueryInterface
* @see https://www.drupal.org/node/2266845
*/
function node_load_multiple(array $nids = NULL, $reset = FALSE) {
@trigger_error('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', E_USER_DEPRECATED);
if ($reset) {
\Drupal::entityManager()->getStorage('node')->resetCache($nids);
}
......
<?php
namespace Drupal\Tests\node\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/**
* Tests legacy user functionality.
*
* @group user
* @group legacy
*/
class NodeLegacyTest extends EntityKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create the node bundles required for testing.
$type = NodeType::create([
'type' => 'page',
'name' => 'page',
]);
$type->save();
$this->installSchema('node', 'node_access');
}
/**
* @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
*/
public function testEntityLegacyCode() {
$this->assertCount(0, node_load_multiple());
Node::create([
'type' => 'page',
'title' => $this->randomMachineName(),
])->save();
$this->assertCount(1, node_load_multiple());
Node::create([
'type' => 'page',
'title' => $this->randomMachineName(),
])->save();
$this->assertCount(2, node_load_multiple());
}
}
......@@ -356,20 +356,20 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
* from the database. Terms are loaded into memory and will not require
* database access if loaded again during the same page request.
*
* @see entity_load_multiple()
* @see \Drupal\Core\Entity\Query\EntityQueryInterface
*
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\taxonomy\Entity\Term::loadMultiple().
*
* @param array $tids
* (optional) An array of entity IDs. If omitted, all entities are loaded.
*
* @return array
* An array of taxonomy term entities, indexed by tid. When no results are
* found, an empty array is returned.
*
* @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
*/
function taxonomy_term_load_multiple(array $tids = NULL) {
@trigger_error('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', E_USER_DEPRECATED);
return Term::loadMultiple($tids);
}
......@@ -380,18 +380,19 @@ function taxonomy_term_load_multiple(array $tids = NULL) {
* vocabulary from the database. Terms are loaded into memory and will not
* require database access if loaded again during the same page request.
*
* @see entity_load_multiple()
*
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\taxonomy\Entity\Vocabulary::loadMultiple().
*
* @param array $vids
* (optional) An array of entity IDs. If omitted, all entities are loaded.
*
* @return array
* An array of vocabulary objects, indexed by vid.
*
* @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
*/
function taxonomy_vocabulary_load_multiple(array $vids = NULL) {
@trigger_error('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', E_USER_DEPRECATED);
return Vocabulary::loadMultiple($vids);
}
......
<?php
namespace Drupal\Tests\taxonomy\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
/**
* Tests legacy user functionality.
*
* @group user
* @group legacy
*/
class TaxonomyLegacyTest extends KernelTestBase {
use TaxonomyTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['filter', 'taxonomy', 'text', 'user'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['filter']);
$this->installEntitySchema('taxonomy_term');
}
/**
* @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
*/
public function testEntityLegacyCode() {
$this->assertCount(0, taxonomy_term_load_multiple());
$this->assertCount(0, taxonomy_vocabulary_load_multiple());
$this->createTerm($this->createVocabulary());
$this->assertCount(1, taxonomy_term_load_multiple());
$this->assertCount(1, taxonomy_vocabulary_load_multiple());
$vocab = $this->createVocabulary();
$this->createTerm($vocab);
$this->createTerm($vocab);
$this->assertCount(3, taxonomy_term_load_multiple());
$this->assertCount(2, taxonomy_vocabulary_load_multiple());
}
}
<?php
namespace Drupal\Tests\user\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
/**
* Tests legacy user functionality.
*
* @group user
* @group legacy
*/
class UserLegacyTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['system', 'user', 'field'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
}
/**
* @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
*/
public function testEntityLegacyCode() {
$this->installSchema('system', ['sequences']);
$this->assertCount(0, user_load_multiple());
User::create(['name' => 'foo'])->save();
$this->assertCount(1, user_load_multiple());
User::create(['name' => 'bar'])->save();
$this->assertCount(2, user_load_multiple());
}
}
......@@ -200,16 +200,13 @@ function user_entity_extra_field_info() {
* @return array
* An array of user objects, indexed by uid.
*
* @see entity_load_multiple()
* @see \Drupal\user\Entity\User::load()
* @see user_load_by_mail()
* @see user_load_by_name()
* @see \Drupal\Core\Entity\Query\QueryInterface
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use
* \Drupal\user\Entity\User::loadMultiple().
*
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\user\Entity\User::loadMultiple().
* @see https://www.drupal.org/node/2266845
*/
function user_load_multiple(array $uids = NULL, $reset = FALSE) {
@trigger_error('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', E_USER_DEPRECATED);
if ($reset) {
\Drupal::entityManager()->getStorage('user')->resetCache($uids);
}
......
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests legacy entity functions.
*
* @group entity
* @group legacy
*/
class EntityLegacyTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['entity_test', 'user'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('entity_test_mul');
}
/**
* @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
*/
public function testEntityLegacyCode() {
$this->assertCount(0, entity_load_multiple('entity_test'));
$this->assertCount(0, entity_load_multiple('entity_test_mul'));
EntityTest::create(['name' => 'published entity'])->save();
$this->assertCount(1, entity_load_multiple('entity_test'));
$this->assertCount(0, entity_load_multiple('entity_test_mul'));
EntityTest::create(['name' => 'published entity'])->save();
EntityTestMul::create(['name' => 'published entity'])->save();
$this->assertCount(2, entity_load_multiple('entity_test'));
$this->assertCount(1, entity_load_multiple('entity_test_mul'));
}
}
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