You are here

public function Upload::buildConfigurationForm in Media entity document 8

File

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

Class

Upload
Uses upload to create media entity documents.

Namespace

Drupal\media_entity_document\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' => 'document',
  ]);

  /** @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 Document 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;
}