You are here

public function CommerceSmartImporerService::createVocabulary in Commerce Smart Importer 8

Creates vocabulary.

File

src/Plugin/CommerceSmartImporerService.php, line 590
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function createVocabulary($name, $vid = FALSE) {
  if ($vid === FALSE) {
    $vid = strtolower($name);
    $vid = str_replace(' ', '_', $vid);
  }
  $vocabularies = Vocabulary::loadMultiple();
  if (!isset($vocabularies[$vid])) {
    $vocabulary = Vocabulary::create([
      'vid' => $vid,
      'description' => '',
      'name' => $name,
    ]);
    $vocabulary
      ->save();
  }
  return $vid;
}