Question
How to create a taxonomy Vocabulary programmatically on Drupal 8 ?
Exaple:
$vid = "new_voc_id";
$name = "New Name";
$vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
if (!isset($vocabularies[$vid])) {
$vocabulary = \Drupal\taxonomy\Entity\Vocabulary::create(array(
'vid' => $vid, //'machine_name' => $vid,
'description' => '',
'name' => $name,
));
$vocabulary->save();
}
else {
// Vocabulary Already exist
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vid);
$tids = $query->execute();
}
Comments
File for above code
Hi, Can you please let me know the filepath and file name where the above code is to be replaced with.
You must create a new module…
You must create a new module like this.
nice .helpfull …
nice .helpfull .
do you have any link for complete reference changes in vocab from D7 and D8
machine_name is not used
machine_name is not used
Need to use:
https://api.drupal.org/api/drupal/core!modules!taxonomy!src!Entity!Vocabulary.php/class/Vocabulary/8.2.x
Thank you
Thank you !!!
Well, that is right about…
Well, that is right about the reality and strong thought about them. <a href="http://papersowl.me/">View website</a> to know and get more knowledge about the matter.
Add new comment