You are here

protected function SoundcloudForm::getMediaType in Media entity Soundcloud 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/SoundcloudForm.php \Drupal\media_entity_soundcloud\Form\SoundcloudForm::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.

Overrides AddFormBase::getMediaType

File

src/Form/SoundcloudForm.php, line 55

Class

SoundcloudForm

Namespace

Drupal\media_entity_soundcloud\Form

Code

protected function getMediaType(FormStateInterface $form_state) {
  if ($this->mediaType) {
    return $this->mediaType;
  }
  $media_type = parent::getMediaType($form_state);
  if (!$media_type
    ->getSource() instanceof Soundcloud) {
    throw new \InvalidArgumentException('Can only add media types which use an Soundcloud source plugin.');
  }
  return $media_type;
}