I'm making a tree view of vocabulary terms and I need to link each term to it's page(depends on which link template name is provided as argument to my function).

I'm loading the terms with taxonomy_get_tree and I could get fully loaded entities with it but if the vocabulary grows this will impact performance. So I'm thinking if there is a way to get the route data to build links for the terms without the need to load the whole taxonomy term entities?

I could hard-code the routes because I know them but that would mean that for every new vocabulary or term link template the code would have to be changed which is not much of a solution.

So is there a way to build the route for the provided link template with only term ID?


At least at the moment the route name used for the link is part of the entity type link templates. Once you have fetch that from the entity manager you just have to construct the route parameters for yourself and be relative save. I think it is fine, especially in your custom enviroment, to not rely that hard on other contrib modules.


Even in Drupal 7 https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_uri/7 you needed the full blown entity for the URI to it. There's nothing new here.

  • How about loading just one term, getting the route array an changing the value of taoxnomy_term parameter? Since all terms are from one vocabulary this should not be a problem.
    – user21641
    May 18 '14 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy