You are here

protected function ImporterService::createNewTerm in Hierarchical Taxonomy Import 8

This method adds a new taxonomy term.

Parameters

string $vid: Vocabulary ID.

string $term: Term name

numeric $parent: Parent Term ID.

Return value

numeric Newly create terms ID.

1 call to ImporterService::createNewTerm()
ImporterService::updateActualParent in src/services/ImporterService.php
This method calculates upon CSV data and finds out actual parent.

File

src/services/ImporterService.php, line 201

Class

ImporterService
Class ImporterService.

Namespace

Drupal\hierarchical_taxonomy_importer\services

Code

protected function createNewTerm($vid, $term, $parent) {
  try {

    // Adding a new term to the TAxonomy..
    $new_term = Term::create([
      'name' => $term,
      'parent' => $parent,
      'vid' => $vid,
    ]);
    $new_term
      ->save();
  } catch (\Exception $ex) {
    \Drupal::logger('hti')
      ->error($ex
      ->getMessage());
    return;
  }

  // Newly entered Term ID.
  return $new_term
    ->id();
}