MediaSelection.php in Drupal 10
File
core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.php
View source
<?php
namespace Drupal\media\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
class MediaSelection extends DefaultSelection {
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
if (!$this->currentUser
->hasPermission('administer media')) {
$query
->condition('status', 1);
}
return $query;
}
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
$media = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
$media
->setPublished();
return $media;
}
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
if (!$this->currentUser
->hasPermission('administer media')) {
$entities = array_filter($entities, function ($media) {
return $media
->isPublished();
});
}
return $entities;
}
}
Classes
Name |
Description |
MediaSelection |
Provides specific access control for the media entity type. |