function MediaSelection::createNewEntity

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

Overrides DefaultSelection::createNewEntity

File

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

Class

MediaSelection
Provides specific access control for the media entity type.

Namespace

Drupal\media\Plugin\EntityReferenceSelection

Code

public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
    $media = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
    // In order to create a referenceable media, it needs to published.
    
    /** @var \Drupal\media\MediaInterface $media */
    $media->setPublished();
    return $media;
}

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