protected function createMediaFromValue(MediaTypeInterface
$media_type, EntityStorageInterface
$media_storage,
$source_field_name,
$file) { if (!
($file instanceof FileInterface
)) { throw new \
InvalidArgumentException('Cannot create a media item without a file entity.'
);
} // Create a file item to get the upload location.
$item =
$this->
createFileItem($media_type);
$upload_location =
$item->
getUploadLocation();
if (!
$this->fileSystem->
prepareDirectory($upload_location, FileSystemInterface::CREATE_DIRECTORY
)) { throw new FileWriteException("The destination directory '
$upload_location' is not writable"
);
} $file =
$this->fileRepository->
move($file,
$upload_location);
if (!
$file) { throw new \
RuntimeException("Unable to move file to '
$upload_location'"
);
} return parent::
createMediaFromValue($media_type,
$media_storage,
$source_field_name,
$file);
} /**
* Create a file field item.
*
* @param \Drupal\media\MediaTypeInterface $media_type
* The media type of the media item.
*
* @return \Drupal\file\Plugin\Field\FieldType\FileItem
* A created file item.
*/