0

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?

2 Answers 2

1

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.

2

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.

1
  • 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
    Commented May 18, 2014 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.