Flagging a comment using the following settings:

  • Flag access by content authorship = Users may only flag own comments
  • Display checkbox on entity edit form

It works fine for the comment edit form, but not for new comments. On the new comment form the checkbox never is displayed.

Even do there is an exception on the code to handle the case of new comments:

// Restrict access by comment authorship.
if ($flag->entity_type == 'comment') {
// For non-existent comments (such as on the comment add form), assume that
// the current user is creating the content.
if (empty($entity_id) || !($comment = $flag->fetch_entity($entity_id))) {

CommentFileSizeAuthor
#2 flag_access_for_new-2579905-2.patch627 bytesBlanca.Esqueda
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Blanca.Esqueda created an issue. See original summary.

Blanca.Esqueda’s picture

Status: Active » Needs review
FileSize
627 bytes

For some reason the if statement to check the comment add form is not working. I assume it was working before or maybe it still works for some specific cases.
The next condition is always false:

if (empty($entity_id) || !($comment = $flag->fetch_entity($entity_id))) {

$entity_id is not empty but its value is 'new' for the comment add form.

And $flag->fetch_entity($entity_id) neither is empty or null, for the comment add form it generates an array:
stdClass Object
(
[nid] => 6
[name] =>
[mail] =>
[homepage] =>
[subject] =>
[comment] =>
[cid] =>
[pid] =>
[language] => und
[uid] => 0
[node_type] => comment_node_discussion
)

Including $entity_id == 'new' to the condition statement resolves this issue.

joachim’s picture

Thanks for the patch!

Fix makes sense.

For the look of the thing, I think I would have put the check for 'new' before calling $flag->fetch_entity(), because when you read that expression it looks like that's going to incur a query. It turns out it doesn't, as it has a special case for 'new' as well. But I think this patch is fine as it is -- I'll commit it later.

It also looks like from a read of the code that the node case has the same problem.

joachim’s picture

Status: Needs review » Fixed

Fixed. Thanks again!

Looking at this area of code again, I think there are other bugs here.

    if (empty($entity_id) || !($node = $flag->fetch_entity($entity_id))) {
      return $flag->access_author == 'others' ? FALSE : NULL;
    }

If 'access_author' is NOT 'others', we return NULL, which means 'no opinion'. No further checks are done, so if the setting is 'node_own' or 'node_others', then it's being ignored.

I'll file a new issue for that: #2592435: flag on new comment form doesn't take node authorship access options into account.

There's also the same problem you found, but for nodes: #2592429: flag access for new nodes doesn't take into account the nid being set to 'new'

  • joachim committed 6bf834c on 7.x-3.x authored by Blanca.Esqueda
    Issue #2579905 by Blanca.Esqueda: Fixed flag access for new comments in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.