You are here

protected function FileUploadForm::prepareMediaEntityForSave in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::prepareMediaEntityForSave()

Prepares a created media item to be permanently saved.

Parameters

\Drupal\media\MediaInterface $media: The unsaved media item.

Overrides AddFormBase::prepareMediaEntityForSave

File

core/modules/media_library/src/Form/FileUploadForm.php, line 344

Class

FileUploadForm
Creates a form to create media entities from uploaded files.

Namespace

Drupal\media_library\Form

Code

protected function prepareMediaEntityForSave(MediaInterface $media) {

  /** @var \Drupal\file\FileInterface $file */
  $file = $media
    ->get($this
    ->getSourceFieldName($media->bundle->entity))->entity;
  $file
    ->setPermanent();
  $file
    ->save();
}