protected function TermParentsTest::createTerm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::createTerm()
- 9 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::createTerm()
Creates a term, saves it and returns it.
Parameters
string $name: The name of the term to create
int[] $parent_ids: (optional) A list of parent term IDs.
Return value
\Drupal\taxonomy\TermInterface The created term.
File
- core/
modules/ taxonomy/ tests/ src/ Functional/ TermParentsTest.php, line 262
Class
- TermParentsTest
- Tests managing taxonomy parents through the user interface.
Namespace
Drupal\Tests\taxonomy\FunctionalCode
protected function createTerm($name, array $parent_ids = []) {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $this->termStorage
->create([
'name' => $name,
'vid' => $this->vocabularyId,
]);
foreach ($parent_ids as $delta => $parent_id) {
$term
->get('parent')
->set($delta, [
'target_id' => $parent_id,
]);
}
$term
->save();
return $term;
}