7

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

12

vid is the vocabulary machine name, in Drupal 8. You just need to pass the the string you have to TermStorage::loadTree(), without changing it.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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