You are here

private function FixturesDataTrait::createTerm in Acquia Lift Connector 8

Same name and namespace in other branches
  1. 8.3 src/Tests/FixturesDataTrait.php \Drupal\acquia_lift\Tests\FixturesDataTrait::createTerm()

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 src/Tests/SettingsTest.php
Sets up a Drupal site for running functional and integration tests.

File

src/Tests/FixturesDataTrait.php, line 49
Contains \Drupal\acquia_lift\Tests\FixturesDataTrait.

Class

FixturesDataTrait
Fixtures Data Trait.

Namespace

Drupal\acquia_lift\Tests

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