private function TermMatcherTest::createTerm in Linkit 8.4
Creates and saves a new term with 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 TermMatcherTest::createTerm()
- TermMatcherTest::setUp in src/
Tests/ Matchers/ TermMatcherTest.php - Sets up a Drupal site for running functional and integration tests.
File
- src/
Tests/ Matchers/ TermMatcherTest.php, line 69 - Contains \Drupal\linkit\Tests\Matchers\TermMatcherTest.
Class
- TermMatcherTest
- Tests term matcher.
Namespace
Drupal\linkit\Tests\MatchersCode
private function createTerm(Vocabulary $vocabulary, $values = array()) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$termStorage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$term = $termStorage
->create($values + array(
'name' => $this
->randomMachineName(),
'description' => array(
'value' => $this
->randomMachineName(),
// Use the first available text format.
'format' => $format
->id(),
),
'vid' => $vocabulary
->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$term
->save();
return $term;
}