Commit a80dcbe3 authored by larowlan's avatar larowlan

Issue #3030629 by Berdir, alexpott, dww: Properly deprecate all the methods in...

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