You are here

public function MediaSelection::createNewEntity in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.php \Drupal\media\Plugin\EntityReferenceSelection\MediaSelection::createNewEntity()
  2. 9 core/modules/media/src/Plugin/EntityReferenceSelection/MediaSelection.php \Drupal\media\Plugin\EntityReferenceSelection\MediaSelection::createNewEntity()

File

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

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;
}