You are here

protected function PhotosMediaLibraryForm::getMediaType in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/Form/PhotosMediaLibraryForm.php \Drupal\photos\Form\PhotosMediaLibraryForm::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 PhotosMediaLibraryForm::getMediaType()
PhotosMediaLibraryForm::buildInputElement in src/Form/PhotosMediaLibraryForm.php
Builds the element for submitting source field value(s).

File

src/Form/PhotosMediaLibraryForm.php, line 29

Class

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

Namespace

Drupal\photos\Form

Code

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