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

CooleWampe created an issue. See original summary.

CooleWampe’s picture

Issue summary: View changes
nachosalvador’s picture

Status: Active » Postponed (maintainer needs more info)

Hello! @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.

CooleWampe’s picture

I wanted to use this snippet in an module-install-script, it doesn't work with a variable.

CooleWampe’s picture

The code was a module-install-script. Every try to install the module failed with the error-message above.

CooleWampe’s picture

Status: Postponed (maintainer needs more info) » Active

Version: 8.0.0-beta15 » 8.0.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.0.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Status: Active » Closed (cannot reproduce)
Issue tags: -taxonomy_term bundle +Bug Smash Initiative

Just 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!