Retrieving a term tree for a specific vocabulary in Drupal 8 requires the vocabulary ID. I can find no function/method/service that will return the vocabulary entity given the machine name, in order to get the vocabulary ID.

How do I get a vocabulary ID from its machine name?

1 Answer 1


The vid field is the machine name for a vocabulary in Drupal 8.

You just need to pass the the string you have to TermStorage::loadTree, it doesn't need to be altered. For example:

$terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree("myname");
  • 1
    That would certainly explain why I couldn't find one! Thanks, Clive!
    – JAyenGreen
    Mar 6, 2017 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.