Commit 0b82131c 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 aeda6d3a
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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');
    if (!empty($vid)) {
      return $this->entityTypeManager->getStorage('taxonomy_vocabulary')->load($vid);
    }
    else {
      return NULL;
    }
  }

}
+20 −0
Original line number Diff line number Diff line
@@ -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');
  }

}