function AddFormBase::getMediaType
Same name in other branches
- 9 core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaType()
- 8.9.x core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaType()
- 10 core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaType()
Get the media type from the form state.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The current form state.
Return value
\Drupal\media\MediaTypeInterface The media type.
Throws
\InvalidArgumentException If the selected media type does not exist.
3 calls to AddFormBase::getMediaType()
- AddFormBase::processInputValues in core/
modules/ media_library/ src/ Form/ AddFormBase.php - Creates media items from source field input values.
- FileUploadForm::getMediaType in core/
modules/ media_library/ src/ Form/ FileUploadForm.php - Get the media type from the form state.
- OEmbedForm::getMediaType in core/
modules/ media_library/ src/ Form/ OEmbedForm.php - Get the media type from the form state.
2 methods override AddFormBase::getMediaType()
- FileUploadForm::getMediaType in core/
modules/ media_library/ src/ Form/ FileUploadForm.php - Get the media type from the form state.
- OEmbedForm::getMediaType in core/
modules/ media_library/ src/ Form/ OEmbedForm.php - Get the media type from the form state.
File
-
core/
modules/ media_library/ src/ Form/ AddFormBase.php, line 114
Class
- AddFormBase
- Provides a base class for creating media items from within the media library.
Namespace
Drupal\media_library\FormCode
protected function getMediaType(FormStateInterface $form_state) {
if ($this->mediaType) {
return $this->mediaType;
}
$state = $this->getMediaLibraryState($form_state);
$selected_type_id = $state->getSelectedTypeId();
$this->mediaType = $this->entityTypeManager
->getStorage('media_type')
->load($selected_type_id);
if (!$this->mediaType) {
throw new \InvalidArgumentException("The '{$selected_type_id}' media type does not exist.");
}
return $this->mediaType;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.