diff --git a/core/modules/forum/src/Controller/ForumController.php b/core/modules/forum/src/Controller/ForumController.php index 501bfa4425d1eef5ec1af0cba6cee9aeefd4a9d8..347013b812c60d0100884ed197dcf0cdb97f21cf 100644 --- a/core/modules/forum/src/Controller/ForumController.php +++ b/core/modules/forum/src/Controller/ForumController.php @@ -154,7 +154,7 @@ public static function create(ContainerInterface $container) { public function forumPage(TermInterface $taxonomy_term) { // Get forum details. $taxonomy_term->forums = $this->forumManager->getChildren($this->config('forum.settings')->get('vocabulary'), $taxonomy_term->id()); - $taxonomy_term->parents = $this->forumManager->getParents($taxonomy_term->id()); + $taxonomy_term->parents = $this->termStorage->loadAllParents($taxonomy_term->id()); if (empty($taxonomy_term->forum_container->value)) { $build = $this->forumManager->getTopics($taxonomy_term->id(), $this->currentUser()); diff --git a/core/modules/forum/src/ForumManager.php b/core/modules/forum/src/ForumManager.php index 29e03e1cb7f4ddd2d85a78e49b8b7439d1e32ab6..e8be2869e898d64f574949e1cd247655148620ef 100644 --- a/core/modules/forum/src/ForumManager.php +++ b/core/modules/forum/src/ForumManager.php @@ -480,6 +480,7 @@ public function resetCache() { * {@inheritdoc} */ public function getParents($tid) { + @trigger_error(__NAMESPACE__ . '\ForumManager::getParents() is deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Call loadAllParents() on taxonomy term storage directly. See https://www.drupal.org/node/3069599', E_USER_DEPRECATED); return $this->entityTypeManager->getStorage('taxonomy_term')->loadAllParents($tid); } diff --git a/core/modules/forum/src/ForumManagerInterface.php b/core/modules/forum/src/ForumManagerInterface.php index 9e8833ebcf356c0ed202fa3920f7e8a501bd1086..f1f7079ec5fbc4838010786f1643ff145d686ff3 100644 --- a/core/modules/forum/src/ForumManagerInterface.php +++ b/core/modules/forum/src/ForumManagerInterface.php @@ -60,8 +60,10 @@ public function resetCache(); * @return array * Array of parent terms. * - * @deprecated Scheduled to be removed in 9.0.x, see - * https://www.drupal.org/node/2371593. + * @deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Call + * loadAllParents() on taxonomy term storage directly. + * + * @see https://www.drupal.org/node/3069599 */ public function getParents($tid); diff --git a/core/modules/forum/tests/src/Kernel/LegacyForumTest.php b/core/modules/forum/tests/src/Kernel/LegacyForumTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fdd610aa26904bbaca5151b331c649472d5229bb --- /dev/null +++ b/core/modules/forum/tests/src/Kernel/LegacyForumTest.php @@ -0,0 +1,69 @@ +<?php + +namespace Drupal\Tests\forum\Kernel; + +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests Legacy forum code. + * + * @group forum + * @group legacy + */ +class LegacyForumTest extends KernelTestBase { + + protected static $modules = [ + 'comment', + 'forum', + 'system', + 'taxonomy', + 'text', + 'user', + ]; + + /** + * The taxonomy term storage. + * + * @var \Drupal\taxonomy\TermStorage + */ + protected $termStorage; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('taxonomy_term'); + $this->installConfig('forum'); + $this->termStorage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); + } + + /** + * Tests the getParents() method. + * + * @expectedDeprecation Drupal\forum\ForumManager::getParents() is deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Call loadAllParents() on taxonomy term storage directly. See https://www.drupal.org/node/3069599 + */ + public function testGetParents() { + // Add a forum. + $forum = $this->termStorage->create([ + 'name' => 'Forum', + 'vid' => 'forums', + 'forum_container' => 1, + ]); + $forum->save(); + + // Add a container. + $subforum = $this->termStorage->create([ + 'name' => 'Subforum', + 'vid' => 'forums', + 'forum_container' => 0, + 'parent' => $forum->id(), + ]); + $subforum->save(); + + $legacy_parents = \Drupal::service('forum_manager')->getParents($subforum->id()); + $parents = $this->termStorage->loadAllParents($subforum->id()); + $this->assertSame($parents, $legacy_parents); + } + +}