function FileUploadForm::getMediaType

Same name in other branches
  1. 9 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::getMediaType()
  2. 8.9.x core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::getMediaType()
  3. 11.x core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::getMediaType()

Overrides AddFormBase::getMediaType

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

File

core/modules/media_library/src/Form/FileUploadForm.php, line 125

Class

FileUploadForm
Creates a form to create media entities from uploaded files.

Namespace

Drupal\media_library\Form

Code

protected function getMediaType(FormStateInterface $form_state) {
    if ($this->mediaType) {
        return $this->mediaType;
    }
    $media_type = parent::getMediaType($form_state);
    // The file upload form only supports media types which use a file field as
    // a source field.
    $field_definition = $media_type->getSource()
        ->getSourceFieldDefinition($media_type);
    if (!is_a($field_definition->getClass(), FileFieldItemList::class, TRUE)) {
        throw new \InvalidArgumentException('Can only add media types which use a file field as a source field.');
    }
    return $media_type;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.