Skip to content
Snippets Groups Projects

Comment admins cannot reply to unpublished comments (despite link)

Open Mohit Aghera requested to merge issue/drupal-221761:221761-comment-admins-cannot into 11.x
Files
5
@@ -296,8 +296,11 @@ public function replyFormAccess(EntityInterface $entity, $field_name, $pid = NUL
// Load the parent comment.
$comment = $this->entityTypeManager()->getStorage('comment')->load($pid);
// Check if the parent comment is published and belongs to the entity.
$access = $access->andIf(AccessResult::allowedIf($comment && $comment->isPublished() && $comment->getCommentedEntityId() == $entity->id()));
// Check if the parent comment is published or user can administer
// comments, and parent comment belongs to the entity.
    • Comment on lines +298 to +299
      Maintainer
      Suggested change
      298 // Check if the parent comment is published or user can administer
      299 // comments, and parent comment belongs to the entity.
      298 // Access is allowed if:
      299 // - The parent comment is published or the user can administer comments.
      300 // - The parent comment belongs to the entity.
Please register or sign in to reply
$access = $access->andIf(AccessResult::allowedIf($comment &&
($comment->isPublished() || $account->hasPermission('administer comments')) &&
$comment->getCommentedEntityId() == $entity->id()));
    • Comment on lines +300 to +302
      Maintainer

      This is trying to win the Longest Line of Code Award.™ Ideally should either spread the logic out onto multiple readable lines, or define single use variables like $is_published, $administer_comments, and $is_entity for readability.

Please register or sign in to reply
if ($comment) {
$access->addCacheableDependency($comment);
}
Loading