private function TermMatcherTest::createTerm in Linkit 8.5
Creates and saves a new term with in vocabulary $vid.
Parameters
\Drupal\taxonomy\VocabularyInterface $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 TermMatcherTest::createTerm()
- TermMatcherTest::setUp in tests/
src/ Kernel/ Matchers/ TermMatcherTest.php
File
- tests/
src/ Kernel/ Matchers/ TermMatcherTest.php, line 139
Class
- TermMatcherTest
- Tests term matcher.
Namespace
Drupal\Tests\linkit\Kernel\MatchersCode
private function createTerm(VocabularyInterface $vocabulary, array $values = []) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$termStorage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$term = $termStorage
->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;
}