You are here

protected function AddFormBase::getMediaType in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media_library/src/Form/AddFormBase.php \Drupal\media_library\Form\AddFormBase::getMediaType()
  2. 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 116

Class

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

Namespace

Drupal\media_library\Form

Code

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;
}