You are here

public function QuickTermTrait::createTerm in farmOS 2.x

Create a term.

Parameters

array $values: An array of values to initialize the term with.

Return value

\Drupal\taxonomy\TermInterface The term entity that was created.

2 calls to QuickTermTrait::createTerm()
QuickTermTrait::createOrLoadTerm in modules/core/quick/src/Traits/QuickTermTrait.php
Given a term name, create or load a matching term entity.
Test::submitForm in modules/core/quick/tests/modules/farm_quick_test/src/Plugin/QuickForm/Test.php
Form submission handler.

File

modules/core/quick/src/Traits/QuickTermTrait.php, line 21

Class

QuickTermTrait
Provides methods for working with terms.

Namespace

Drupal\farm_quick\Traits

Code

public function createTerm(array $values = []) {

  // Alias 'vocabulary' to 'vid'.
  if (!empty($values['vocabulary'])) {
    $values['vid'] = $values['vocabulary'];
  }

  // Start a new term entity with the provided values.

  /** @var \Drupal\taxonomy\TermInterface $term */
  $term = Term::create($values);

  // Save the term.
  $term
    ->save();

  // Return the term entity.
  return $term;
}