Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I think it's a bug - this can't be a feature. Error while creating taxonomy terms via php-script. It seems, not to be allowed to use a private variable for setting the "vid" in the "taxonomy_term". If a public variable or method is used everything fine, but local variables always failed.
$vocabularyMachineName = 'example_vocabulary';
$vocNode = array(
'name' => 'Example Vokabulary',
'vid' => $vocabularyMachineName,
'description' => 'Descripe this vocabulary',
);
\Drupal::entityManager()->getStorage('taxonomy_vocabulary')->create($vocNode)->save();
$termNode = array(
'vid' =>$vocabularyMachineName,
'name' => 'Example Taxonomy',
'description' => 'Describe this Taxonomy',
);
\Drupal::entityManager()->getStorage('taxonomy_term')->create($termNode)->save();
Comments
Comment #2
CooleWampe CreditAttribution: CooleWampe commentedComment #3
nachosalvador CreditAttribution: nachosalvador as a volunteer commentedHello! @unstatu and I tried to reproduce the reported issue at DrupalCon 2015 Barcelona and we couldn't. Can you describe a little bit more how to reproduce it? Because we launched the script with the drush core-cli tool and the script was executed correctly and the Example Taxonomy was created fine.
Comment #4
CooleWampe CreditAttribution: CooleWampe commentedI wanted to use this snippet in an module-install-script, it doesn't work with a variable.
Comment #5
CooleWampe CreditAttribution: CooleWampe commentedThe code was a module-install-script. Every try to install the module failed with the error-message above.
Comment #6
CooleWampe CreditAttribution: CooleWampe commentedComment #9
quietone CreditAttribution: quietone as a volunteer commentedJust like #3 I was not able to reproduce this error. I test on Drupal 8.9.x
Therefore, closing as cannot reproduce. If you are experiencing this problem reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!