How can I get the term ID out of the hierarchical select theming function? I'm attempting to add a link to flag each term output by hierarchical select in a views template.

Here's the relevant code from hs_taxonomy.module:

function theme_hs_taxonomy_formatter_lineage($variables) {
  $output = '';
  $lineage = $variables['lineage'];
  $separator = theme('hierarchical_select_item_separator');
  dpm($variables);

  // Render each item within a lineage.
  $items = array();
  foreach ($lineage as $level =&gt; $item ) {
    dpm($lineage);
    $line  = '&lt;span class="lineage-item lineage-item-level-' . $level . '"&gt;';
    $line .= drupal_render($item);
    $line .= '&lt;/span&gt;';
    dpm($item);
    $items[] = $line;
  }
  $output .= implode($separator, $items);

  return $output;
}


And here's the output of dpm($item):


Based on the flag module documentation, I tried to add the link like this: $line .= flag_create_link('hobbies', $term-&gt;$item['#options']['entity']['tid']);

But that gives this error:
Fatal error: Cannot use object of type stdClass as array in /mysite/sites/all/modules/contrib/hierarchical_select/modules/hs_taxonomy.module on line 880

How can I get the tid of the term being output?
The entity is a stdClass object, you need to use the -&gt; accessor:

flag_create_link('hobbies', $term-&gt;$item['#options']['entity']-&gt;tid);