Get vocabulary by name in Drupal 8+

0
928
Get vocabulary by name in Drupal 8+
Get vocabulary by name in Drupal 8+

In this post, I will share with you a snippet to get vocabulary by name in Drupal 8+.

function getVocabularyByName($vocabularyName) {
    $vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
    foreach ($vocabularies as $v) {
        if ($v->id() == $vocabularyName) {
            return $v;
        }
    }
    return NULL;
}