Commit a6b5766a authored by catch's avatar catch
Browse files

Issue #2774399 by mohit_aghera, joebot, Munavijayalakshmi, rensingh99,...

Issue #2774399 by mohit_aghera, joebot, Munavijayalakshmi, rensingh99, borisson_, Chi, quietone: Fatal error on accessing module uninstall page with Forum enabled

(cherry picked from commit b3af2575)
parent 74834309
......@@ -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;
}
}
}
......@@ -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');
}
}
Supports Markdown
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