You are here

protected function FileSelection::buildEntityQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php \Drupal\file\Plugin\EntityReferenceSelection\FileSelection::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/file/src/Plugin/EntityReferenceSelection/FileSelection.php, line 28
Contains \Drupal\file\Plugin\EntityReferenceSelection\FileSelection.

Class

FileSelection
Provides specific access control for the file entity type.

Namespace

Drupal\file\Plugin\EntityReferenceSelection

Code

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

  // Allow referencing :
  // - files with status "permanent"
  // - or files uploaded by the current user (since newly uploaded files only
  //   become "permanent" after the containing entity gets validated and
  //   saved.)
  $query
    ->condition($query
    ->orConditionGroup()
    ->condition('status', FILE_STATUS_PERMANENT)
    ->condition('uid', $this->currentUser
    ->id()));
  return $query;
}