You are here

public static function Vocabularies::loadByName in Hook Update Deploy Tools 7

Load a Vocabulary from its human readable name.

Parameters

string $vocabulary_name: The human readable name of a Vocabulary.

bool $strict: Flag to cause exception to be thrown if not able to load.

Return value

object The Vocabulary object if found.

Throws

\HudtException if it can not be found.

1 call to Vocabularies::loadByName()
Terms::loadByName in src/Terms.php
Load a term by name.

File

src/Vocabularies.php, line 254

Class

Vocabularies
Public methods for dealing with Vocabularies.

Namespace

HookUpdateDeployTools

Code

public static function loadByName($vocabulary_name, $strict = FALSE) {
  Check::canUse('taxonomy');
  Check::canCall('taxonomy_get_vocabularies');

  // Grab all the Vocabularies.
  $vocabularies = taxonomy_get_vocabularies(NULL);

  // Look for the vocabulary.
  foreach ($vocabularies as $vocabulary) {
    if (!empty($vocabulary) && $vocabulary->name === $vocabulary_name) {
      return $vocabulary;
    }
  }
  if ($strict) {

    // The Vocabulary was not found, throw exception, call this a failure.
    $message = "There is no Vocabulary '@!name'. It could not be loaded.";
    $variables = array(
      '@name' => $vocabulary_name,
    );
    throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
  }
  else {
    return FALSE;
  }
}