0

I have a table with entities of type content, taxonomy_vocabulary and terms. For content and terms, I can show a link to each detail page by using the method entity_uri.

But for entities with type taxonomy_vocabulary this does not work, entity_uri returns null.

What is the best way to get the url for a taxonomy_vocabulary entity?

1
  • Taxonomy doesn't come with a default page to view a vocabulary. So I guess that is why entity_uri has nothing to return in this case. I am happy to get the admin page for the vocabulary, but that is not what is pretended in most cases. I think there should be a default detail page for each vocabulary, listing its terms. And then entity_uri should return that uri natively.
    – dxvargas
    Sep 13, 2016 at 6:47

1 Answer 1

1

I hope it is not the best answer, because it requires customized code. But anyway, it is a possible solution and I'll share it.

/**
 * Implements hook_entity_info().
 */
function mymodule_entity_info_alter(&$info) {
  if (isset($info['taxonomy_vocabulary'])) {
    $info['taxonomy_vocabulary']['uri callback'] = 'my_module_entity_info_uri_callback';
  }
}

/**
 * Return path for taxonomy_vocabulary entities
 */
function my_module_entity_info_uri_callback($taxonomy) {
  return array(
    'path' => 'admin/structure/taxonomy/' . $taxonomy->machine_name,
  );
}

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.