FileSelection.php in Drupal 8
File
core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php
View source
<?php
namespace Drupal\file\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
class FileSelection extends DefaultSelection {
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$query
->condition($query
->orConditionGroup()
->condition('status', FILE_STATUS_PERMANENT)
->condition('uid', $this->currentUser
->id()));
return $query;
}
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
$file = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
$file
->setPermanent();
return $file;
}
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
$entities = array_filter($entities, function ($file) {
return $file
->isPermanent() || $file
->getOwnerId() === $this->currentUser
->id();
});
return $entities;
}
}
Classes
Name |
Description |
FileSelection |
Provides specific access control for the file entity type. |