You are here

public function MediaFileUpload::getForm in Panopoly 8.2

File

modules/panopoly/panopoly_media/src/Plugin/EntityBrowser/Widget/MediaFileUpload.php, line 35

Class

MediaFileUpload
Uses upload to create media images.

Namespace

Drupal\panopoly_media\Plugin\EntityBrowser\Widget

Code

public function getForm(array &$original_form, FormStateInterface $form_state, array $aditional_widget_parameters) {

  /** @var \Drupal\media\MediaTypeInterface $media_type */
  if (!$this->configuration['media_type'] || !($media_type = $this->entityTypeManager
    ->getStorage('media_type')
    ->load($this->configuration['media_type']))) {
    return [
      '#markup' => $this
        ->t('The media type is not configured correctly.'),
    ];
  }
  if ($media_type
    ->getSource()
    ->getPluginId() != 'file') {
    return [
      '#markup' => $this
        ->t('The configured media type is not using the file plugin.'),
    ];
  }
  $form = parent::getForm($original_form, $form_state, $aditional_widget_parameters);
  $form['upload']['#upload_validators']['file_validate_extensions'] = [
    $this->configuration['extensions'],
  ];
  return $form;
}