function _bef_test_add_term in Better Exposed Filters 8.3
Same name and namespace in other branches
- 8.5 tests/modules/bef_test/bef_test.install \_bef_test_add_term()
- 8.4 tests/modules/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.
1 call to _bef_test_add_term()
- bef_test_install in tests/
bef_test/ bef_test.install - Adds terms to the hierarchical "location" vocabulary.
File
- tests/
bef_test/ bef_test.install, line 71
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();
}