Is it better to create a taxonomy term using the 'create' method of the base Entity class or the entity storage manager?

by Matt   Last Updated December 27, 2017 16:07 PM

I've seen multiple ways to programmatically create entities.

In this case I'm creating a taxonomy term. One is using this method

$term = \Drupal\taxonomy\Entity\Term::create([
  'name' => $name, 
  'vid' => $vocabulary,

Where I'm using the base entity class's public static create function. Another way to perform the action is using an entity storage manager. Like so:

$term = [
  'name'     => $name,
  'vid'      => $vocabulary,

$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create($term);

I looked up the 'create' function of the base Entity class and it seems to just be implementing what appears in the second example I provided. Is there a better practice between the two? Or does it not matter?

Related Questions

how to get all children's tid drupal 8

Updated March 31, 2018 16:07 PM

Adding vocabularyterm/ references to entity types

Updated July 23, 2017 21:07 PM