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');

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

  return $output;

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

Based on the flag module documentation, I tried to add the link like this: $line .= flag_create_link('hobbies', $term->$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?

1 Answer 1


The entity is a stdClass object, you need to use the -> accessor:

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

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.