I am trying to make a link on node by returning this array(The array is being formed in the function by the name buildLinks() ):

     $links[$key] = array(

    'title' => $definition['title'],

    'href' => $this->urlGenerator->generateFromRoute('module.show_format.' . $entity->getEntityTypeId(), array('module_format' => $key, 'entity' => $entity->id())),

but on the page the link title is appearing but the link's href value gets lost(I mean title is appearing but it is not appearing as link).What am I doing wrong?

Update: The above array is being returned over here:

    return array(
    '#theme' => 'links__entity__module',
    '#links' => $this->linkBuilder->buildLinks($this->request->attributes->get($entity_type)),

So is there is a possiblity that I am doing something wrong over here?

  • are you sure the $this-> is actually returning a correct value?
    – Geoff
    May 22, 2015 at 5:46
  • @Geoff yes $this-> is working correctly... May 23, 2015 at 15:27

1 Answer 1


Looks like the documentation around that theme function is out of date. Please open a bug report for that.

Have a look at template_preprocess_links, it is using url, not href. Also not that url is a Drupal\Core\Url object, not a path, so your code should look like this:

$links[$key] = array(
  'title' => $definition['title'],
  'url' => Url::fromRoute('module.show_format.' . $entity->getEntityTypeId(), array('module_format' => $key, 'entity' => $entity->id())),

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.