You are here

public function MediaImageUpload::buildConfigurationForm in Entity Browser 8.2

Implements PluginFormInterface::buildConfigurationForm().

Overrides Upload::buildConfigurationForm

File

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

Class

MediaImageUpload
Uses upload to create media images.

Namespace

Drupal\entity_browser\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,
  ];
  $media_type_options = [];
  $media_types = $this->entityTypeManager
    ->getStorage('media_type')
    ->loadByProperties([
    'source' => 'image',
  ]);
  foreach ($media_types as $media_type) {
    $media_type_options[$media_type
      ->id()] = $media_type
      ->label();
  }
  if (empty($media_type_options)) {
    $url = Url::fromRoute('entity.media_type.add_form')
      ->toString();
    $form['media_type'] = [
      '#markup' => $this
        ->t("You don't have media type of the Image type. You should <a href='!link'>create one</a>", [
        '!link' => $url,
      ]),
    ];
  }
  else {
    $form['media_type'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Media type'),
      '#default_value' => $this->configuration['media_type'],
      '#options' => $media_type_options,
    ];
  }
  return $form;
}