You are here

protected function AddFormBase::createMediaFromValue in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::createMediaFromValue()
  2. 9 core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::createMediaFromValue()

Creates a new, unsaved media item from a source field value.

Parameters

\Drupal\media\MediaTypeInterface $media_type: The media type of the media item.

\Drupal\Core\Entity\EntityStorageInterface $media_storage: The media storage.

string $source_field_name: The name of the media type's source field.

mixed $source_field_value: The value for the source field of the media item.

Return value

\Drupal\media\MediaInterface An unsaved media entity.

1 call to AddFormBase::createMediaFromValue()
AddFormBase::processInputValues in core/modules/media_library/src/Form/AddFormBase.php
Creates media items from source field input values.

File

core/modules/media_library/src/Form/AddFormBase.php, line 532

Class

AddFormBase
Provides a base class for creating media items from within the media library.

Namespace

Drupal\media_library\Form

Code

protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value) {
  $media = $media_storage
    ->create([
    'bundle' => $media_type
      ->id(),
    $source_field_name => $source_field_value,
  ]);
  $media
    ->setName($media
    ->getName());
  return $media;
}