My View spews a bunch of these:

Notice: Trying to get property of non-object in views_handler_field_comment_link->render_link() (regel 55 van sites/all/modules/contrib/views/modules/comment/views_handler_field_comment_link.inc).
Notice: Trying to get property of non-object in views_handler_field_comment_link->render_link() (regel 56 van sites/all/modules/contrib/views/modules/comment/views_handler_field_comment_link.inc).
Notice: Trying to get property of non-object in comment_access() (regel 1447 van modules/comment/comment.module).
Notice: Trying to get property of non-object in views_handler_field_comment_link_edit->render_link() (regel 48 van sites/all/modules/contrib/views/modules/comment/views_handler_field_comment_link_edit.inc).

because my View has a Comment: Child comment relationship that doesn't always return a comment.

views_handler_field_comment_link::render() doesn't check if there's a comment to render an edit link for:

  function render($values) {
    $value = $this->get_value($values, 'cid');
    return $this->render_link($this->sanitize_value($value), $values);
  }

The above $value is empty if there's no comment, the cid otherwise.

Fix is easy:

  function render($values) {
    $value = $this->get_value($values, 'cid');
    if (!$value) {
      return '';
    }
    return $this->render_link($this->sanitize_value($value), $values);
  }

If there's no comment, don't render an edit link.

Comments

jantoine’s picture

Version: 7.x-3.11 » 7.x-3.x-dev
Component: Miscellaneous » comment data
Status: Active » Needs review
StatusFileSize
new1.97 KB

I just ran into the same issue, however the suggested fix doesn't just change the edit link, but changes the view link as well breaking the 'Link field to the node if there is no comment.' feature. The attached patch fixes all errors without breaking features and also prevents the edit link from appearing if there is no comment.

jantoine’s picture

Title: Edit comment link notices when relating to non-existent child comment » Edit comment link causes PHP notices and is visible by unathroized users if no comment exists
jantoine’s picture

Title: Edit comment link causes PHP notices and is visible by unathroized users if no comment exists » Edit comment link causes PHP notices and is visible by unauthroized users if no comment exists
rudiedirkx’s picture

You mean this part?

// If there is no comment link to the node.
else if ($this->options['link_to_node']) {

Yeah, I didn't check there. Looks good, but can't try it right now.

rudiedirkx’s picture

Status: Needs review » Needs work

I get these:

Notice: Undefined variable: nid in views_handler_field_comment_link->render_link() (line 67 of ../views/modules/comment/views_handler_field_comment_link.inc).

because $nid is defined in the if, and used in another elseif.

If there's no comment to link to, there's no way of knowing the (alleged) parent nid. I dont think the If there is no comment link to the node part is possible.