drupal-6drupal-modulesdrupal-hooks

Finding out which hook to use


I am working on a module which does something similar to nodereferences_url.

Which Drupal hook to implement to place a link in link into a node content area like is highlighted in the attached image?

enter image description here


Solution

  • It is hook_link(), which is described as:

    This hook enables modules to add links to many parts of Drupal. Links may be added in nodes or in the navigation block, for example.

    The returned array should be a keyed array of link entries. Each link can be in one of two formats.

    An example of implementation of that hook is node_link(), that contains the following code:

    function node_link($type, $node = NULL, $teaser = FALSE) {
      $links = array();
    
      if ($type == 'node') {
        if ($teaser == 1 && $node->teaser && !empty($node->readmore)) {
          $links['node_read_more'] = array(
            'title' => t('Read more'), 
            'href' => "node/$node->nid",
            // The title attribute gets escaped when the links are processed, so
            // there is no need to escape here. 
            'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title))),
          );
        }
      }
    
      return $links;
    }
    

    That is the code that adds the "Read more" link in the teaser of a node, when the node content is more than the content already shown in the teaser.

    To notice that the hook is called for nodes, and comments. As described in the documentation, the $type parameter can have the following values: