You are here

public function Drupal8::newVocabularyTerm in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::newVocabularyTerm()
  2. 7.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::newVocabularyTerm()

Creates a new vocabulary term.

Parameters

object $vocabulary: The vocabulary object.

string $name: The name of the new taxonomy term.

Return value

object The taxonomy term object.

Overrides Framework::newVocabularyTerm

File

api/src/Framework/Drupal8.php, line 393

Class

Drupal8
Drupal 8-specific code.

Namespace

Drupal\realistic_dummy_content_api\Framework

Code

public function newVocabularyTerm($vocabulary, $name) {
  $term = Term::create([
    'name' => $name,
    'vid' => $vocabulary
      ->id(),
  ]);
  $term
    ->save();
  return $term;
}