Getting to a taxonomy term value that doesn't have its own method

The most oft used properties of a taxonomy term have their own methods, like term::getName(). But what do you do when you need a value that does not?

An example of this is the vocabulary ID (vid). This exists in the term an array of a protected member, values. Because of that, one cannot simply reference it as

$term->values['vid']

but this will work

$vid_array = $term->get('vid')->getValue()

Having done that, the value returned is an array. The value is tucked within it and can be accessed with

$my_term_variable[0]['target_id']

 


Of course, the Drupal Community isn't the only place to give back. It's a complex world, and there are as many worthy causes as their are melodies, with most being served by multiple charitable organizations. Here are a few of those that strike a 7th chord with me.