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! Commented Mar 6, 2017 at 16:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.