From 39aae61be559ee0b1c96ef197204857065177387 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Wed, 16 Nov 2022 16:48:31 +0000 Subject: [PATCH] Issue #3111785 by longwave, Spokje, andypost, xjm, catch, Berdir, alexpott: Properly deprecate TermStorage::deleteTermHierarchy() and ::updateTermHierarchy() --- core/modules/taxonomy/src/TermStorage.php | 8 ++++-- .../taxonomy/src/TermStorageInterface.php | 14 ++++++---- .../tests/src/Kernel/TermKernelTest.php | 28 +++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php index 5d1332a44777..c01ae66d3adb 100644 --- a/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -91,12 +91,16 @@ public function resetCache(array $ids = NULL) { /** * {@inheritdoc} */ - public function deleteTermHierarchy($tids) {} + public function deleteTermHierarchy($tids) { + @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. It is a no-op since 8.6.0. Parent references are automatically cleared when deleting a taxonomy term. See https://www.drupal.org/node/2936675', E_USER_DEPRECATED); + } /** * {@inheritdoc} */ - public function updateTermHierarchy(EntityInterface $term) {} + public function updateTermHierarchy(EntityInterface $term) { + @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. It is a no-op since 8.6.0. Parent references are automatically updated when updating a taxonomy term. See https://www.drupal.org/node/2936675', E_USER_DEPRECATED); + } /** * {@inheritdoc} diff --git a/core/modules/taxonomy/src/TermStorageInterface.php b/core/modules/taxonomy/src/TermStorageInterface.php index 29401868d782..41d521156aba 100644 --- a/core/modules/taxonomy/src/TermStorageInterface.php +++ b/core/modules/taxonomy/src/TermStorageInterface.php @@ -16,9 +16,10 @@ interface TermStorageInterface extends ContentEntityStorageInterface { * @param array $tids * Array of terms that need to be removed from hierarchy. * - * @todo Remove this method in Drupal 9.0.x. Now the parent references are - * automatically cleared when deleting a taxonomy term. - * https://www.drupal.org/node/2785693 + * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Parent + * references are automatically cleared when deleting a taxonomy term. + * + * @see https://www.drupal.org/node/2936675 */ public function deleteTermHierarchy($tids); @@ -28,9 +29,10 @@ public function deleteTermHierarchy($tids); * @param \Drupal\Core\Entity\EntityInterface $term * Term entity that needs to be added to term hierarchy information. * - * @todo remove this method Drupal 9.0.x. Now the parent references are - * automatically updates when a taxonomy term is added/updated. - * https://www.drupal.org/node/2785693 + * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Parent + * references are automatically updated when updating a taxonomy term. + * + * @see https://www.drupal.org/node/2936675 */ public function updateTermHierarchy(EntityInterface $term); diff --git a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php index 29e43b72bf56..820924bfeb84 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php @@ -168,4 +168,32 @@ public function testTermPreview() { $this->assertNotEmpty(trim($rendered), 'Term is able to be rendered.'); } + /** + * @covers \Drupal\taxonomy\TermStorage::deleteTermHierarchy + * @group legacy + */ + public function testDeleteTermHierarchyDeprecation(): void { + $vocabulary = $this->createVocabulary(); + $term = $this->createTerm($vocabulary); + + /** @var \Drupal\taxonomy\TermStorageInterface $storage */ + $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); + $this->expectDeprecation('Drupal\taxonomy\TermStorage::deleteTermHierarchy() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. It is a no-op since 8.6.0. Parent references are automatically cleared when deleting a taxonomy term. See https://www.drupal.org/node/2936675'); + $storage->deleteTermHierarchy([$term->tid]); + } + + /** + * @covers \Drupal\taxonomy\TermStorage::updateTermHierarchy + * @group legacy + */ + public function testUpdateTermHierarchyDeprecation(): void { + $vocabulary = $this->createVocabulary(); + $term = $this->createTerm($vocabulary); + + /** @var \Drupal\taxonomy\TermStorageInterface $storage */ + $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); + $this->expectDeprecation('Drupal\taxonomy\TermStorage::updateTermHierarchy() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. It is a no-op since 8.6.0. Parent references are automatically updated when updating a taxonomy term. See https://www.drupal.org/node/2936675'); + $storage->updateTermHierarchy($term); + } + } -- GitLab