function TermTest::reloadTermByName

Same name in other branches
  1. 10 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::reloadTermByName()
  2. 11.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::reloadTermByName()

Reloads a term by name.

Parameters

string $name: The name of the term.

Return value

\Drupal\taxonomy\TermInterface The reloaded term.

1 call to TermTest::reloadTermByName()
TermTest::testTermMultipleParentsInterface in core/modules/taxonomy/tests/src/Functional/TermTest.php
Tests saving a term with multiple parents through the UI.

File

core/modules/taxonomy/tests/src/Functional/TermTest.php, line 615

Class

TermTest
Tests load, save and delete for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

private function reloadTermByName(string $name) : TermInterface {
    \Drupal::entityTypeManager()->getStorage('taxonomy_term')
        ->resetCache();
    
    /** @var \Drupal\taxonomy\TermInterface[] $terms */
    $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
        ->loadByProperties([
        'name' => $name,
    ]);
    return reset($terms);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.