You are here

protected function OEmbedForm::getMediaType in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media_library/src/Form/OEmbedForm.php \Drupal\media_library\Form\OEmbedForm::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

1 call to OEmbedForm::getMediaType()
OEmbedForm::buildInputElement in core/modules/media_library/src/Form/OEmbedForm.php
Builds the element for submitting source field value(s).

File

core/modules/media_library/src/Form/OEmbedForm.php, line 82

Class

OEmbedForm
Creates a form to create media entities from oEmbed URLs.

Namespace

Drupal\media_library\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 OEmbedInterface) {
    throw new \InvalidArgumentException('Can only add media types which use an oEmbed source plugin.');
  }
  return $media_type;
}