You are here

protected function CommentSelection::buildEntityQuery in Comment Permissions 8

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 CommentSelection::buildEntityQuery

File

src/Plugin/EntityReferenceSelection/CommentSelection.php, line 19

Class

CommentSelection
Overrides CommentSelection plugin.

Namespace

Drupal\comment_perm\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
    ->userHasAdminPerm()) {

    // Add specific tag to alter query later and remove status condition.
    $query
      ->addTag('comment_perm_access');
  }
  else {
    $query
      ->condition('status', CommentInterface::PUBLISHED);
  }
  return $query;
}