Same name and namespace in other branches
  1. 9 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.

8 calls to taxonomy_term_load_multiple_by_name()
EntityReferenceAutoCreateTest::testMultipleTargetBundles in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php
Tests if an entity reference field having multiple target bundles is storing the auto-created entity in the right destination.
TermLanguageTest::testTermLanguage in core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php
TermLanguageTest::testTermTranslatedOnOverviewPage in core/modules/taxonomy/tests/src/Functional/TermLanguageTest.php
Tests that translated terms are displayed correctly on the term overview.
TermTest::testNodeTermCreationAndDeletion in core/modules/taxonomy/tests/src/Functional/TermTest.php
Test term creation with a free-tagging vocabulary from the node form.
TermTest::testTaxonomyGetTermByName in core/modules/taxonomy/tests/src/Functional/TermTest.php
Test taxonomy_term_load_multiple_by_name().

... See full list

File

core/modules/taxonomy/taxonomy.module, line 359
Enables the organization of content into categories.

Code

function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
  $values = [
    'name' => trim($name),
  ];
  if (isset($vocabulary)) {
    $vocabularies = taxonomy_vocabulary_get_names();
    if (isset($vocabularies[$vocabulary])) {
      $values['vid'] = $vocabulary;
    }
    else {

      // Return an empty array when filtering by a non-existing vocabulary.
      return [];
    }
  }
  return \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadByProperties($values);
}