function taxonomy_term_load_multiple_by_name in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/taxonomy.module \taxonomy_term_load_multiple_by_name()
Try to map a string to an existing term, as for glossary use.
Provides a case-insensitive and trimmed mapping, to maximize the likelihood of a successful match.
Parameters
$name: Name of the term to search for.
$vocabulary: (optional) Vocabulary machine name to limit the search. Defaults to NULL.
Return value
An array of matching term objects.
Deprecated
in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->loadByProperties(['name' => $name, 'vid' => $vid]) instead, to get a list of taxonomy term entities having the same name and keyed by their term ID.
See also
https://www.drupal.org/node/3039041
1 call to taxonomy_term_load_multiple_by_name()
- TermTest::testTaxonomyGetTermByName in core/
modules/ taxonomy/ tests/ src/ Functional/ TermTest.php - Tests taxonomy_term_load_multiple_by_name().
File
- core/
modules/ taxonomy/ taxonomy.module, line 222 - Enables the organization of content into categories.
Code
function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
@trigger_error('taxonomy_term_load_multiple_by_name() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \\Drupal::entityTypeManager()->getStorage("taxonomy_vocabulary")->loadByProperties(["name" => $name, "vid" => $vid]) instead, to get a list of taxonomy term entities having the same name and keyed by their term ID. See https://www.drupal.org/node/3039041', E_USER_DEPRECATED);
$values = [
'name' => trim($name),
];
if (isset($vocabulary)) {
$values['vid'] = $vocabulary;
}
return \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties($values);
}