diff --git a/core/modules/forum/src/ForumUninstallValidator.php b/core/modules/forum/src/ForumUninstallValidator.php index face3cbf459c363d8b3be1cae276f53c11ee81ac..a67caac31694c0fc3464824e57dbfd9872a3f0ee 100644 --- a/core/modules/forum/src/ForumUninstallValidator.php +++ b/core/modules/forum/src/ForumUninstallValidator.php @@ -58,7 +58,7 @@ public function validate($module) { } $vocabulary = $this->getForumVocabulary(); - if ($this->hasTermsForVocabulary($vocabulary)) { + if (!empty($vocabulary) && $this->hasTermsForVocabulary($vocabulary)) { if ($vocabulary->access('view')) { $reasons[] = $this->t('To uninstall Forum, first delete all <a href=":url">%vocabulary</a> terms', [ '%vocabulary' => $vocabulary->label(), @@ -117,7 +117,12 @@ protected function hasTermsForVocabulary(VocabularyInterface $vocabulary) { */ protected function getForumVocabulary() { $vid = $this->configFactory->get('forum.settings')->get('vocabulary'); - return $this->entityTypeManager->getStorage('taxonomy_vocabulary')->load($vid); + if (!empty($vid)) { + return $this->entityTypeManager->getStorage('taxonomy_vocabulary')->load($vid); + } + else { + return NULL; + } } } diff --git a/core/modules/forum/tests/src/Functional/ForumUninstallTest.php b/core/modules/forum/tests/src/Functional/ForumUninstallTest.php index 30ea8c1fd07a61f6f1c47b18b575e621f0f123ba..1e2c6fa66e90c477a84f6c7bbe348022fd449b01 100644 --- a/core/modules/forum/tests/src/Functional/ForumUninstallTest.php +++ b/core/modules/forum/tests/src/Functional/ForumUninstallTest.php @@ -7,6 +7,7 @@ use Drupal\node\Entity\NodeType; use Drupal\comment\Entity\Comment; use Drupal\taxonomy\Entity\Term; +use Drupal\taxonomy\Entity\Vocabulary; use Drupal\Tests\BrowserTestBase; /** @@ -159,4 +160,23 @@ public function testForumUninstallWithoutFieldStorage() { $this->container->get('module_installer')->uninstall(['forum']); } + /** + * Tests uninstallation of forum module when vocabulary is deleted. + */ + public function testForumUninstallWithoutForumVocabulary() { + $this->drupalLogin($this->rootUser); + Vocabulary::load('forums')->delete(); + + // Now attempt to uninstall forum. + $this->drupalGet('admin/modules/uninstall'); + $this->assertSession()->responseNotContains('The website encountered an unexpected error. Please try again later'); + $this->assertSession()->statusCodeEquals(200); + + // Assert forum is no longer required. + $this->assertSession()->fieldExists('uninstall[forum]'); + + $this->drupalGet('admin/modules/uninstall'); + $this->submitForm(['uninstall[forum]' => 1], 'Uninstall'); + } + }