function TermParentsTest::createTerm

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::createTerm()
  2. 8.9.x core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::createTerm()
  3. 11.x 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.

4 calls to TermParentsTest::createTerm()
TermParentsTest::doTestEditingSingleParent in core/modules/taxonomy/tests/src/Functional/TermParentsTest.php
Performs tests that edit terms with a single parent.
TermParentsTest::testEditingParents in core/modules/taxonomy/tests/src/Functional/TermParentsTest.php
Tests editing the parents of existing terms.
TermParentsTest::testEditingParentsWithDisabledFormElement in core/modules/taxonomy/tests/src/Functional/TermParentsTest.php
Tests specifying parents when creating terms and a disabled parent form.
TermParentsTest::testParentFromQuery in core/modules/taxonomy/tests/src/Functional/TermParentsTest.php
Test the term add/edit form with parent query parameter.

File

core/modules/taxonomy/tests/src/Functional/TermParentsTest.php, line 312

Class

TermParentsTest
Tests managing taxonomy parents through the user interface.

Namespace

Drupal\Tests\taxonomy\Functional

Code

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;
}

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