You are here

public function Upload::buildConfigurationForm in Media entity video 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/EntityBrowser/Widget/Upload.php \Drupal\media_entity_video\Plugin\EntityBrowser\Widget\Upload::buildConfigurationForm()
  2. 8.2 src/Plugin/EntityBrowser/Widget/Upload.php \Drupal\media_entity_video\Plugin\EntityBrowser\Widget\Upload::buildConfigurationForm()

File

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

Class

Upload
Uses upload to create media entity videos.

Namespace

Drupal\media_entity_video\Plugin\EntityBrowser\Widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $bundle_options = [];
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['extensions'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Allowed extensions'),
    '#default_value' => $this->configuration['extensions'],
    '#required' => TRUE,
  ];
  $bundles = $this->entityTypeManager
    ->getStorage('media_bundle')
    ->loadByProperties([
    'type' => 'video',
  ]);

  /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
  foreach ($bundles as $bundle) {
    $bundle_options[$bundle
      ->id()] = $bundle
      ->label();
  }
  if (empty($bundle_options)) {
    $url = Url::fromRoute('media.bundle_add')
      ->toString();
    $form['media bundle'] = [
      '#markup' => $this
        ->t("You don't have media bundle of the Video type. You should <a href='!link'>create one</a>", [
        '!link' => $url,
      ]),
    ];
  }
  else {
    $form['media bundle'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Media bundle'),
      '#default_value' => $this->configuration['media bundle'],
      '#options' => $bundle_options,
    ];
  }
  return $form;
}