You are here

public function MediaSelection::createNewEntity in Drupal 9

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

Creates a new entity object that can be used as a valid reference.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle name.

string $label: The entity label.

int $uid: The entity owner ID, if the entity type supports it.

Return value

\Drupal\Core\Entity\EntityInterface An unsaved entity object.

Overrides DefaultSelection::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;
}