Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#4 | 738992-comment_link.patch | 614 bytes | dawehner |
Comments
Comment #1
dawehnerYour 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?
Comment #2
steve.colson CreditAttribution: steve.colson commentedI 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.
Comment #3
steve.colson CreditAttribution: steve.colson commentedBumping for any thoughts?
Comment #4
dawehnerDoes this patch works?
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedThe 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.
Comment #6
MustangGB CreditAttribution: MustangGB commented