You are here

private function FixturesDataTrait::createTerm in Acquia Lift Connector 8.4

Returns a new term with random properties in vocabulary $vid.

Parameters

\Drupal\taxonomy\Entity\Vocabulary $vocabulary: The vocabulary object.

array $values: (optional) An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

Return value

\Drupal\taxonomy\Entity\Term The new taxonomy term object.

1 call to FixturesDataTrait::createTerm()
SettingsTest::setUp in tests/src/Functional/SettingsTest.php

File

tests/src/Unit/Traits/FixturesDataTrait.php, line 43

Class

FixturesDataTrait
Fixtures Data Trait.

Namespace

Drupal\Tests\acquia_lift\Unit\Traits

Code

private function createTerm(Vocabulary $vocabulary, $values = []) {
  $filter_formats = filter_formats();
  $format = array_pop($filter_formats);
  $term = Term::create($values + [
    'name' => $this
      ->randomMachineName(),
    'description' => [
      'value' => $this
        ->randomMachineName(),
      // Use the first available text format.
      'format' => $format
        ->id(),
    ],
    'vid' => $vocabulary
      ->id(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $term
    ->save();
  return $term;
}