function ForumUninstallValidator::hasTermsForVocabulary

Same name and namespace in other branches
  1. 9 core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary()
  2. 10 core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary()
  3. 11.x core/modules/forum/src/ForumUninstallValidator.php \Drupal\forum\ForumUninstallValidator::hasTermsForVocabulary()

Determines if there are any taxonomy terms for a specified vocabulary.

Parameters

\Drupal\taxonomy\VocabularyInterface $vocabulary: The vocabulary to check for terms.

Return value

bool TRUE if there are terms for this vocabulary, FALSE otherwise.

1 call to ForumUninstallValidator::hasTermsForVocabulary()
ForumUninstallValidator::validate in core/modules/forum/src/ForumUninstallValidator.php
Determines the reasons a module can not be uninstalled.

File

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

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

protected function hasTermsForVocabulary(VocabularyInterface $vocabulary) {
    $terms = $this->entityTypeManager
        ->getStorage('taxonomy_term')
        ->getQuery()
        ->condition('vid', $vocabulary->id())
        ->accessCheck(FALSE)
        ->range(0, 1)
        ->execute();
    return !empty($terms);
}

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