function FileSelection::buildEntityQuery

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

Overrides DefaultSelection::buildEntityQuery

File

core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php, line 24

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', FileInterface::STATUS_PERMANENT)
        ->condition('uid', $this->currentUser
        ->id()));
    return $query;
}

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