function MediaSelection::validateReferenceableNewEntities

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

Overrides DefaultSelection::validateReferenceableNewEntities

File

core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.php, line 50

Class

MediaSelection
Provides specific access control for the media entity type.

Namespace

Drupal\media\Plugin\EntityReferenceSelection

Code

public function validateReferenceableNewEntities(array $entities) {
    $entities = parent::validateReferenceableNewEntities($entities);
    // Mirror the conditions checked in buildEntityQuery().
    if (!$this->currentUser
        ->hasPermission('administer media')) {
        $entities = array_filter($entities, function ($media) {
            
            /** @var \Drupal\media\MediaInterface $media */
            return $media->isPublished();
        });
    }
    return $entities;
}

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