Issue #3030629 by Berdir, alexpott, dww: Properly deprecate all the methods in entity.inc that are not called by core
parent
f91dd64fc5
commit
a80dcbe3f1
|
@ -44,10 +44,12 @@ function entity_render_cache_clear() {
|
|||
* \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo() for
|
||||
* all bundles.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3051077
|
||||
* @see \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getBundleInfo()
|
||||
* @see \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo()
|
||||
*/
|
||||
function entity_get_bundles($entity_type = NULL) {
|
||||
@trigger_error('entity_get_bundles() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getBundleInfo() for a single bundle, or \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo() for all bundles. See https://www.drupal.org/node/3051077', E_USER_DEPRECATED);
|
||||
if (isset($entity_type)) {
|
||||
return \Drupal::entityManager()->getBundleInfo($entity_type);
|
||||
}
|
||||
|
@ -95,20 +97,13 @@ function entity_load($entity_type, $id, $reset = FALSE) {
|
|||
* The entity object, or NULL if there is no entity with the given revision
|
||||
* id.
|
||||
*
|
||||
* @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* the entity storage's loadRevision() method to load a specific entity
|
||||
* revision:
|
||||
* @code
|
||||
* \Drupal::entityTypeManager()
|
||||
* ->getStorage($entity_type)
|
||||
* ->loadRevision($revision_id);
|
||||
* @endcode
|
||||
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
|
||||
* entity type storage's loadRevision() method.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
|
||||
* @see \Drupal\Core\Entity\EntityStorageInterface::loadRevision()
|
||||
* @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage
|
||||
* @see https://www.drupal.org/node/1818376
|
||||
*/
|
||||
function entity_revision_load($entity_type, $revision_id) {
|
||||
@trigger_error('entity_revision_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage\'s loadRevision() method. See https://www.drupal.org/node/1818376', E_USER_DEPRECATED);
|
||||
return \Drupal::entityManager()
|
||||
->getStorage($entity_type)
|
||||
->loadRevision($revision_id);
|
||||
|
@ -122,19 +117,13 @@ function entity_revision_load($entity_type, $revision_id) {
|
|||
* @param $revision_id
|
||||
* The revision ID to delete.
|
||||
*
|
||||
* @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* the entity storage's deleteRevision() method to delete a specific entity
|
||||
* revision:
|
||||
* @code
|
||||
* \Drupal::entityTypeManager()
|
||||
* ->getStorage($entity_type)
|
||||
* ->deleteRevision($revision_id);
|
||||
* @endcode
|
||||
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
|
||||
* entity type storage's deleteRevision() method.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
|
||||
* @see \Drupal\Core\Entity\EntityStorageInterface::deleteRevision()
|
||||
* @see https://www.drupal.org/node/1818376
|
||||
*/
|
||||
function entity_revision_delete($entity_type, $revision_id) {
|
||||
@trigger_error('entity_revision_delete() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage\'s deleteRevision() method. See https://www.drupal.org/node/1818376', E_USER_DEPRECATED);
|
||||
\Drupal::entityManager()
|
||||
->getStorage($entity_type)
|
||||
->deleteRevision($revision_id);
|
||||
|
@ -229,16 +218,13 @@ function entity_load_multiple_by_properties($entity_type, array $values) {
|
|||
* @return \Drupal\Core\Entity\EntityInterface|null
|
||||
* The unchanged entity, or FALSE if the entity cannot be loaded.
|
||||
*
|
||||
* @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* the entity storage's loadUnchanged() method to load an unchanged entity:
|
||||
* @code
|
||||
* \Drupal::entityTypeManager()->getStorage($entity_type)->loadUnchanged($id);
|
||||
* @endcode
|
||||
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
|
||||
* entity type storage's loadUnchanged() method.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
|
||||
* @see \Drupal\Core\Entity\EntityStorageInterface::loadUnchanged()
|
||||
* @see https://www.drupal.org/node/1935744
|
||||
*/
|
||||
function entity_load_unchanged($entity_type, $id) {
|
||||
@trigger_error('entity_load_unchanged() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage\'s loadUnchanged() method. See https://www.drupal.org/node/1935744', E_USER_DEPRECATED);
|
||||
return \Drupal::entityManager()
|
||||
->getStorage($entity_type)
|
||||
->loadUnchanged($id);
|
||||
|
@ -313,15 +299,14 @@ function entity_create($entity_type, array $values = []) {
|
|||
* @return string|null
|
||||
* The label of the entity, or NULL if there is no label defined.
|
||||
*
|
||||
* @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* the entity's label() method to get the label of the entity:
|
||||
* @code
|
||||
* $entity->label($langcode);
|
||||
* @endcode
|
||||
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
|
||||
* entity's label() method.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2549923
|
||||
* @see \Drupal\Core\Entity\EntityInterface::label()
|
||||
*/
|
||||
function entity_page_label(EntityInterface $entity, $langcode = NULL) {
|
||||
@trigger_error('entity_page_label() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity\'s label() method. See https://www.drupal.org/node/2549923', E_USER_DEPRECATED);
|
||||
return $entity->label($langcode);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
|||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
use Drupal\entity_test\Entity\EntityTestRev;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
|
@ -30,11 +31,17 @@ class EntityLegacyTest extends KernelTestBase {
|
|||
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
$this->installEntitySchema('entity_test_rev');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @expectedDeprecation entity_get_bundles() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getBundleInfo() for a single bundle, or \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo() for all bundles. See https://www.drupal.org/node/3051077
|
||||
* @expectedDeprecation entity_page_label() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity's label() method. See https://www.drupal.org/node/2549923
|
||||
* @expectedDeprecation entity_revision_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage's loadRevision() method. See https://www.drupal.org/node/1818376
|
||||
* @expectedDeprecation entity_revision_delete() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage's deleteRevision() method. See https://www.drupal.org/node/1818376
|
||||
* @expectedDeprecation entity_load_unchanged() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage's loadUnchanged() method. See https://www.drupal.org/node/1935744
|
||||
*/
|
||||
public function testEntityLegacyCode() {
|
||||
$this->assertCount(0, entity_load_multiple('entity_test'));
|
||||
|
@ -51,6 +58,24 @@ class EntityLegacyTest extends KernelTestBase {
|
|||
|
||||
$this->assertNull(entity_load('entity_test', 100));
|
||||
$this->assertInstanceOf(EntityInterface::class, entity_load('entity_test', 1));
|
||||
|
||||
$this->assertEquals(['entity_test' => ['label' => 'Entity Test Bundle']], entity_get_bundles('entity_test'));
|
||||
$this->assertEquals(['entity_test' => ['label' => 'Entity Test Bundle']], entity_get_bundles()['entity_test']);
|
||||
|
||||
$entity = EntityTestRev::create(['name' => 'revision test']);
|
||||
$entity->save();
|
||||
$this->assertEquals('revision test', entity_page_label($entity));
|
||||
$first_revision_id = $entity->getRevisionId();
|
||||
$entity->setNewRevision(TRUE);
|
||||
$entity->save();
|
||||
$first_revision = entity_revision_load($entity->getEntityTypeId(), $first_revision_id);
|
||||
$this->assertEquals($first_revision_id, $first_revision->getRevisionId());
|
||||
entity_revision_delete($entity->getEntityTypeId(), $first_revision_id);
|
||||
$this->assertNull(entity_revision_load($entity->getEntityTypeId(), $first_revision_id));
|
||||
|
||||
$entity->setName('Different name');
|
||||
$entity = entity_load_unchanged($entity->getEntityTypeId(), $entity->id());
|
||||
$this->assertEquals('revision test', $entity->label());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue