diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-03-01 21:09:58 -0800 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-03-01 21:09:58 -0800 |
commit | 9749406ba02b277b8e30c21b640cbf17cf50b265 (patch) | |
tree | 72b8d56724981cd0b5762384d99682715304617b /modules/taxonomy/taxonomy.module | |
parent | 57c4d21ed396a68d671ce219aec59b72de99acbb (diff) | |
download | brdo-9749406ba02b277b8e30c21b640cbf17cf50b265.tar.gz brdo-9749406ba02b277b8e30c21b640cbf17cf50b265.tar.bz2 |
Issue #336697 by oriol_e9g, xjm, jbomb, Davy Van Den Bremt, coltrane, lyricnz: Added Optional vocabulary argument for taxonomy_get_term_by_name().
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r-- | modules/taxonomy/taxonomy.module | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 3879efdb6..c920344c6 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -1095,12 +1095,25 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities * * @param $name * Name of the term to search for. + * @param $vocabulary + * (optional) Vocabulary machine name to limit the search. Defaults to NULL. * * @return * An array of matching term objects. */ -function taxonomy_get_term_by_name($name) { - return taxonomy_term_load_multiple(array(), array('name' => trim($name))); +function taxonomy_get_term_by_name($name, $vocabulary = NULL) { + $conditions = array('name' => trim($name)); + if (isset($vocabulary)) { + $vocabularies = taxonomy_vocabulary_get_names(); + if (isset($vocabularies[$vocabulary])) { + $conditions['vid'] = $vocabularies[$vocabulary]->vid; + } + else { + // Return an empty array when filtering by a non-existing vocabulary. + return array(); + } + } + return taxonomy_term_load_multiple(array(), $conditions); } /** |