function ForumUninstallValidator::validate

Same name in this branch
  1. 9 core/modules/forum/src/ProxyClass/ForumUninstallValidator.php \Drupal\forum\ProxyClass\ForumUninstallValidator::validate()
Same name in other branches
  1. 8.9.x core/modules/forum/src/ProxyClass/ForumUninstallValidator.php \Drupal\forum\ProxyClass\ForumUninstallValidator::validate()
  2. 8.9.x core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::validate()
  3. 10 core/modules/forum/src/ProxyClass/ForumUninstallValidator.php \Drupal\forum\ProxyClass\ForumUninstallValidator::validate()
  4. 10 core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::validate()
  5. 11.x core/modules/forum/src/ProxyClass/ForumUninstallValidator.php \Drupal\forum\ProxyClass\ForumUninstallValidator::validate()
  6. 11.x core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::validate()

Overrides ModuleUninstallValidatorInterface::validate

File

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

Class

ForumUninstallValidator
Prevents forum module from being uninstalled under certain conditions.

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.