protected function AddMediaFormBase::createMediaFromValue in Media Directories 8
Same name and namespace in other branches
- 3.x modules/media_directories_ui/src/Form/AddMediaFormBase.php \Drupal\media_directories_ui\Form\AddMediaFormBase::createMediaFromValue()
- 2.x modules/media_directories_ui/src/Form/AddMediaFormBase.php \Drupal\media_directories_ui\Form\AddMediaFormBase::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.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
\Drupal\media\MediaInterface An unsaved media entity.
2 calls to AddMediaFormBase::createMediaFromValue()
- AddMediaFormBase::processInputValues in modules/
media_directories_ui/ src/ Form/ AddMediaFormBase.php - Creates media items from source field input values.
- MediaCombinedUploadForm::processInputValues in modules/
media_directories_ui/ src/ Form/ MediaCombinedUploadForm.php - Creates media items from source field input values.
File
- modules/
media_directories_ui/ src/ Form/ AddMediaFormBase.php, line 822
Class
- AddMediaFormBase
- Class AddMediaFormBase.
Namespace
Drupal\media_directories_ui\FormCode
protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, FormStateInterface $form_state) {
$media = $media_storage
->create([
'bundle' => $media_type
->id(),
$source_field_name => $source_field_value,
'directory' => $this
->getDirectory($form_state),
]);
$media
->setName($media
->getName());
return $media;
}