I need to get vocabulary ID by term object.Please see attched screenshot for term object.enter image description here


You should be able to use the getVocabularyId() function on the term object like:

$vocabulary_id = $term->getVocabularyId();

See https://api.drupal.org/api/drupal/core%21modules%21taxonomy%21src%21Entity%21Term.php/function/Term%3A%3AgetVocabularyId/8.2.x.

  • 2
    $term->getVocabularyId() is deprecated. Use $term->bundle() instead.
    – JFK
    Sep 21 at 17:45

I think we're supposed to use EntityInterface::bundle now as Term::getVocabularyId is deprecated:

Scheduled for removal before Drupal 9.0.0. Use TermInterface::bundle() instead.

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