You are here

public function ForumUninstallValidator::validate in Drupal 10

Same name in this branch
  1. 10 core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::validate()
  2. 10 core/modules/forum/src/ProxyClass/ForumUninstallValidator.php \Drupal\forum\ProxyClass\ForumUninstallValidator::validate()
Same name and namespace in other branches
  1. 8 core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::validate()
  2. 9 core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::validate()

File

core/modules/forum/src/ForumUninstallValidator.php, line 53

Class

ForumUninstallValidator
Prevents forum module from being uninstalled whilst any forum nodes exist or there are any terms in the forum vocabulary.

Namespace

Drupal\forum

Code

public function validate($module) {
  $reasons = [];
  if ($module == 'forum') {
    if ($this
      ->hasForumNodes()) {
      $reasons[] = $this
        ->t('To uninstall Forum, first delete all <em>Forum</em> content');
    }
    $vocabulary = $this
      ->getForumVocabulary();
    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(),
          ':url' => $vocabulary
            ->toUrl('overview-form')
            ->toString(),
        ]);
      }
      else {
        $reasons[] = $this
          ->t('To uninstall Forum, first delete all %vocabulary terms', [
          '%vocabulary' => $vocabulary
            ->label(),
        ]);
      }
    }
  }
  return $reasons;
}