You are here

public function Upload::getForm in Media entity audio 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/EntityBrowser/Widget/Upload.php \Drupal\media_entity_audio\Plugin\EntityBrowser\Widget\Upload::getForm()

File

src/Plugin/EntityBrowser/Widget/Upload.php, line 34

Class

Upload
Uses upload to create media entity audios.

Namespace

Drupal\media_entity_audio\Plugin\EntityBrowser\Widget

Code

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

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