Hi:

Links variable (the one that includes the standard "read more", number of comments, "add new comment", etc) is generated by drupal core in node.module (read more) and comment.module (comments links).

The problem is that drupal core only knows about full and teaser view modes so the links "read more" and comment number only are shown in teaser view mode. If you, like me, have a teaser extended (teas_ext) view mode, and you want to include this links, there's no easy way to do it.

AFAIK the only way to control what to show, what to hide or what to modify is via hook or theme.

I've needed to create a hook_node_view_alter to show this links in my teas_ext view mode (and to customize them in the way I wanted). I think it would be very useful if DS provides a comment number field, add comment field, new comments field in the same way it provides a read more field by now.

Thanks.

Javi.-

I post the code I've used to customize my site just in case someone need it:

/**
* Implements hook_node_view_alter().
*/
function bwaslala_ui_node_view_alter(&$build) {
  $node=$build['#node'];
  $view_mode=$build['#view_mode'];
  $links=array();
  // Add links for teas_ext view mode (extracted from node.module and comment.module
  if ($view_mode == 'teas_ext') {
    // Read more for teas ext
    $node_title_stripped = strip_tags($node->title);
    $links['node-readmore'] = array(
      'title' => t('Read more<span class="element-invisible"> about @title</span>', array('@title' => $node_title_stripped)),
      'href' => 'node/' . $node->nid,
      'html' => TRUE,
      'attributes' => array('rel' => 'tag', 'title' => $node_title_stripped),
    );
    // Assign links
    $build['links']['node']['#links']=$links;
    // Comments links for teas ext
    $links=array();
    // Teaser view: display the number of comments that have been posted,
    // or a link to add new comments if the user has permission, the node
    // is open to new comments, and there currently are none.
    if (user_access('access comments')) {
      if (!empty($node->comment_count)) {
        $links['comment-comments'] = array(
          'title' => format_plural($node->comment_count, '1 comment', '@count comments'),
          'href' => "node/$node->nid",
          'attributes' => array('title' => t('Jump to the first comment of this posting.')),
          'fragment' => 'comments',
          'html' => TRUE,
        );
      }
    }
    if ($node->comment == COMMENT_NODE_OPEN) {
      if (user_access('post comments')) {
        $links['comment-add'] = array(
          'title' => t('Add new comment'),
          'href' => "comment/reply/$node->nid",
          'attributes' => array('title' => t('Add a new comment to this page.')),
          'fragment' => 'comment-form',
        );
      }
      else {
        $links['comment_forbidden'] = array(
          'title' => theme('comment_post_forbidden', array('node' => $node)),
          'html' => TRUE,
        );
      }
    }
    // Assign links
    $build['links']['comment']['#links']=$links;
  }
  // I only want add new comment link if there is no comment yet (this is applicable to teaser and teas_ext view modes)
  if (isset($build['links']['comment']['#links']['comment-comments'],$build['links']['comment']['#links']['comment-add'])) {
    unset($build['links']['comment']['#links']['comment-add']);
  }
  // I don't want new comments link (too much noise)
  if (isset($build['links']['comment']['#links']['comment-new-comments'])) {
    unset($build['links']['comment']['#links']['comment-new-comments']);
  }
  // Change read more with see more (useful to blog and gallery)
  if (isset($build['links']['node']['#links']['node-readmore'])) {
    $build['links']['node']['#links']['node-readmore']['title']=t('See more<span class="element-invisible"> about @title</span>', array('@title' => $node_title_stripped));
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

heretic381’s picture

This is exactly what I'm looking for.
DS provide an interesting way to customize the read more field, but if want to include the rest of links, that I will have the old read more with the customized one. Is there an easy the get rid of the "read more" link from links field?

heretic381’s picture

Javi, thanks for the code by the way. :)
Although it doesn't really work for me.

Neograph734’s picture

Priority: Normal » Major

I kept thinking I did something wrong, checked everywhere but it appears the links are simply not there... It would be nice to have this added to ds at some point. Perhaps even with checkboxes for what links to show and hide?

But for now, thanks for the code neurojavi!

Neograph734’s picture

Status: Active » Needs review
FileSize
4.43 KB

Attached is my attempt to do this the Display Suite way. I wanted to overwrite the links array in ds_ds_fields_info(), but that resulted in the old array getting rendered, so for now it has become a new field.

Setting to needs review because one of the DS maintainers might have an idea on why I cannot overwrite the other array.