I noticed when I output a link to the comments on a node, but that node has no comments, the link was coming through as "node/#comment-". From modules/comment/views_handler_field_comment_link.inc:

  function render($values) {
    $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
    return l($text, "node/" . $values->{$this->aliases['nid']}, array('html' => TRUE, 'fragment' => "comment-" . $values->{$this->aliases['cid']}));
  }

however $this->aliases['nid'] is getting built, it doesn't seem to actually work properly. If I change it to:

  function render($values) {
    $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
    return l($text, "node/" . $values->nid, array('html' => TRUE, 'fragment' => "comment-" . $values->{$this->aliases['cid']}));
  }

it works properly, (and relies on core for the alias building of links) but I'm really not sure why we would reference our objects in that way. If we are trying to alias nid to comment_nid, then comment_nid is not getting set.

CommentFileSizeAuthor
#4 738992-comment_link.patch614 bytesdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Your approach is not correct, you cannot know the key of the nid of $values, because the nid could come from a relationship. Can you print $this->aliases?

steve.colson’s picture

I know the approach isn't correct long term -- it just gives me the desired results here in the short term while the real bug is tracked down. $this->aliases is properly set with nid => comments_nid, but as I described above, comments_nid is not getting set. When I print_r that and dump it to watchdog, nid has a value but comments_nid does not.

steve.colson’s picture

Bumping for any thoughts?

dawehner’s picture

Status: Active » Needs review
FileSize
614 bytes

Does this patch works?

merlinofchaos’s picture

Status: Needs review » Needs work

The Comment: Link field links to a specific comment. If you're using this field, you should be getting a list of comments, not a list of nodes.

I suppose it's possible that the field should assume that due to a relationship it may be empty and print nothing if there isn't a cid?

In any case, dereine's patch won't do that.

MustangGB’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)