You are here

function taxonomy_term_machine_name_load in Taxonomy Machine Name 7

Same name and namespace in other branches
  1. 8 taxonomy_machine_name.module \taxonomy_term_machine_name_load()

Provides a case-insensitive and trimmed matching.

Parameters

string $machine_name: Machine name of the term to search for.

int|object $vocabulary: Vocabulary machine name to limit the search.

Return value

object|bool Matching term object or FALSE if not found.

2 calls to taxonomy_term_machine_name_load()
MigrateDestinationTermMachineName::findMatchingTerm in ./taxonomy_machine_name.migrate.inc
Attempt to find a term that has the same machine name.
MigrateDestinationTermMachineName::import in ./taxonomy_machine_name.migrate.inc
Import the provided term, using information from the provided row.
1 string reference to 'taxonomy_term_machine_name_load'
taxonomy_machine_name_form_alter in ./taxonomy_machine_name.module
Implements hook_form_alter().

File

./taxonomy_machine_name.module, line 69

Code

function taxonomy_term_machine_name_load($machine_name, $vocabulary) {
  $conditions = array(
    'machine_name' => trim($machine_name),
  );

  // Support for machine_name form callback.
  $args = func_get_args();
  if (isset($args[2]['term']) && is_object($args[2]['term'])) {
    $vocabulary = $args[2]['term']->vocabulary_machine_name;
  }

  // Load vocabulary from its machine name.
  if (is_string($vocabulary)) {
    $vocabularies =& drupal_static(__FUNCTION__);
    if (NULL === $vocabularies) {
      $vocabularies = taxonomy_vocabulary_get_names();
    }
    $vocabulary = $vocabularies[$vocabulary];
  }
  if (is_object($vocabulary)) {
    $conditions['vid'] = $vocabulary->vid;
  }
  elseif (is_numeric($vocabulary)) {
    $conditions['vid'] = (int) $vocabulary;
  }
  else {
    return FALSE;
  }
  $term = taxonomy_term_load_multiple(array(), $conditions);
  return $term ? reset($term) : FALSE;
}