You are here

public function Upload::buildConfigurationForm in Media entity image 8

File

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

Class

Upload
Uses upload to create media entity images.

Namespace

Drupal\media_entity_image\Plugin\EntityBrowser\Widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['extensions'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Allowed extensions'),
    '#default_value' => $this->configuration['extensions'],
    '#required' => TRUE,
  ];
  $bundle_options = [];
  $bundles = $this->entityTypeManager
    ->getStorage('media_bundle')
    ->loadByProperties([
    'type' => 'image',
  ]);
  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 Image 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;
}