You are here

function _bef_test_add_term in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 tests/modules/bef_test/bef_test.install \_bef_test_add_term()
  2. 8.3 tests/bef_test/bef_test.install \_bef_test_add_term()

Adds a new term to the bef_test-location vocabulary.

If a TID is specified in $parent, the new term is added as a child of that term.

Parameters

string $name: The name of the new term.

int $parent: The (optional) TID of the parent term.

Return value

int TID of the newly created term.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

1 call to _bef_test_add_term()
bef_test_install in tests/modules/bef_test/bef_test.install
Adds terms to the hierarchical "location" vocabulary.

File

tests/modules/bef_test/bef_test.install, line 87
Provides install hooks for the BEF Test module.

Code

function _bef_test_add_term($name, $parent = 0) {
  $term = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->create([
    'vid' => 'bef_test_location',
    'name' => $name,
    'parent' => [
      $parent,
    ],
  ]);
  $term
    ->save();
  return $term
    ->id();
}