function CommentSelection::buildEntityQuery

Same name in other branches
  1. 8.9.x core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::buildEntityQuery()
  2. 10 core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::buildEntityQuery()
  3. 11.x core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::buildEntityQuery()

Overrides DefaultSelection::buildEntityQuery

1 call to CommentSelection::buildEntityQuery()
CommentSelection::getReferenceableEntities in core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php
Gets the list of referenceable entities.

File

core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php, line 26

Class

CommentSelection
Provides specific access control for the comment entity type.

Namespace

Drupal\comment\Plugin\EntityReferenceSelection

Code

protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match, $match_operator);
    // Adding the 'comment_access' tag is sadly insufficient for comments:
    // core requires us to also know about the concept of 'published' and
    // 'unpublished'.
    if (!$this->currentUser
        ->hasPermission('administer comments')) {
        $query->condition('status', CommentInterface::PUBLISHED);
    }
    return $query;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.