function TermTranslationViewsTest::setUpTerms

Same name in other branches
  1. 11.x core/modules/taxonomy/tests/src/Functional/Views/TermTranslationViewsTest.php \Drupal\Tests\taxonomy\Functional\Views\TermTranslationViewsTest::setUpTerms()

Setup translated terms in a hierarchy.

1 call to TermTranslationViewsTest::setUpTerms()
TermTranslationViewsTest::setUp in core/modules/taxonomy/tests/src/Functional/Views/TermTranslationViewsTest.php
Sets up the test.

File

core/modules/taxonomy/tests/src/Functional/Views/TermTranslationViewsTest.php, line 109

Class

TermTranslationViewsTest
Tests for views translation.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

protected function setUpTerms() {
    $parent_vid = 0;
    foreach ($this->termTranslationMap as $name => $translation) {
        $term = $this->createTerm([
            'name' => $name,
            'langcode' => $this->baseLangcode,
            'parent' => $parent_vid,
            'vid' => $this->vocabulary
                ->id(),
        ]);
        $term->addTranslation($this->translateToLangcode, [
            'name' => $translation,
        ]);
        $term->save();
        // Each term is nested under the last.
        $parent_vid = $term->id();
        $this->terms[] = $term;
    }
}

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