You are here

protected function MediaSelection::buildEntityQuery in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.php \Drupal\media\Plugin\EntityReferenceSelection\MediaSelection::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/media/src/Plugin/EntityReferenceSelection/MediaSelection.php, line 23

Class

MediaSelection
Provides specific access control for the media entity type.

Namespace

Drupal\media\Plugin\EntityReferenceSelection

Code

protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
  $query = parent::buildEntityQuery($match, $match_operator);

  // Ensure that users with insufficient permission cannot see unpublished
  // entities.
  if (!$this->currentUser
    ->hasPermission('administer media')) {
    $query
      ->condition('status', 1);
  }
  return $query;
}