I want to add a field on each node which links to a particular page where module's controller will act. I want to actually add a link at bottom of node, and I want to do this programmatically. But I am not able to start, and I am very new to this.

Any ideas or suggestions to get me started? Or give me some reference in Drupal core modules or some other type of sample code to do so? I have done this till now to add the link:

function module_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
if (TRUE) {
  $entity->content['links']['module'] = array(
      '#theme' => 'links__entity__module',
      '#links' => $link_builder->buildLinks($entity),

but till now got no success. Am I using correct hook?Also I think that now the question makes sense.

  • Can you please provide more detail on this? Jun 16, 2015 at 10:56
  • @SumitMadan basically I want to add a link at bottom of node.
    – holdnet
    Jun 16, 2015 at 11:09
  • You can add a link field by adding link module. No? Jun 16, 2015 at 11:11
  • @SumitMadan yeah we can do so but how to do so programatically?
    – holdnet
    Jun 16, 2015 at 11:41
  • By writing a custom module, use hook_node_insert to insert the link in field. Or if its a static link then just use template, or hook_node_view. Jun 16, 2015 at 11:43


Your Answer

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

Browse other questions tagged or ask your own question.