You are here

protected function CommentSelection::buildEntityQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::buildEntityQuery()

Builds an EntityQuery to get referenceable entities.

Parameters

string|null $match: (Optional) Text to match the label against. Defaults to NULL.

string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".

Return value

\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions and sorting applied to it.

Overrides DefaultSelection::buildEntityQuery

File

core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php, line 30
Contains \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection.

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;
}