You are here

public function DropzoneJsEbWidget::buildConfigurationForm in DropzoneJS 8

Same name and namespace in other branches
  1. 8.2 modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php \Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget\DropzoneJsEbWidget::buildConfigurationForm()
1 call to DropzoneJsEbWidget::buildConfigurationForm()
MediaEntityDropzoneJsEbWidget::buildConfigurationForm in modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php
1 method overrides DropzoneJsEbWidget::buildConfigurationForm()
MediaEntityDropzoneJsEbWidget::buildConfigurationForm in modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php

File

modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php, line 345

Class

DropzoneJsEbWidget
Provides an Entity Browser widget that uploads new files.

Namespace

Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $configuration = $this->configuration;
  $form['upload_location'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Upload location'),
    '#default_value' => $configuration['upload_location'],
  ];
  $form['dropzone_description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Dropzone drag-n-drop zone text'),
    '#default_value' => $configuration['dropzone_description'],
  ];
  preg_match('%\\d+%', $configuration['max_filesize'], $matches);
  $max_filesize = !empty($matches) ? array_shift($matches) : '1';
  $form['max_filesize'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum size of files'),
    '#min' => '0',
    '#field_suffix' => $this
      ->t('MB'),
    '#default_value' => $max_filesize,
  ];
  $form['extensions'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Allowed file extensions'),
    '#desciption' => $this
      ->t('A space separated list of file extensions'),
    '#default_value' => $configuration['extensions'],
  ];
  $exif_found = \Drupal::service('library.discovery')
    ->getLibraryByName('dropzonejs', 'exif-js');
  $form['clientside_resize'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use client side resizing'),
    '#default_value' => $configuration['clientside_resize'],
  ];
  if (!$exif_found) {
    $form['clientside_resize']['#description'] = $this
      ->t('Requires droopzone version v4.4.0 or higher and the <a href="@exif" target="_blank">exif</a> library.', [
      '@exif' => 'https://github.com/exif-js/exif-js',
    ]);

    // We still want to provide a way to disable this if the library does not
    // exist.
    if ($configuration['clientside_resize'] == FALSE) {
      $form['clientside_resize']['#disabled'] = TRUE;
    }
  }
  $form['resize_width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Max width'),
    '#default_value' => $configuration['resize_width'],
    '#size' => 60,
    '#field_suffix' => 'px',
    '#min' => 0,
    '#states' => [
      'visible' => [
        ':input[name="table[' . $this
          ->uuid() . '][form][clientside_resize]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['resize_height'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Max height'),
    '#default_value' => $configuration['resize_height'],
    '#size' => 60,
    '#field_suffix' => 'px',
    '#min' => 0,
    '#states' => [
      'visible' => [
        ':input[name="table[' . $this
          ->uuid() . '][form][clientside_resize]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['resize_quality'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Resize quality'),
    '#default_value' => $configuration['resize_quality'],
    '#min' => 0,
    '#max' => 1,
    '#step' => 0.1,
    '#states' => [
      'visible' => [
        ':input[name="table[' . $this
          ->uuid() . '][form][clientside_resize]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['resize_method'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Resize method'),
    '#default_value' => $configuration['resize_method'],
    '#options' => [
      'contain' => $this
        ->t('Contain (scale)'),
      'crop' => $this
        ->t('Crop'),
    ],
    '#states' => [
      'visible' => [
        ':input[name="table[' . $this
          ->uuid() . '][form][clientside_resize]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['thumbnail_method'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Thumbnail method'),
    '#default_value' => $configuration['thumbnail_method'],
    '#options' => [
      'contain' => $this
        ->t('Contain (scale)'),
      'crop' => $this
        ->t('Crop'),
    ],
    '#states' => [
      'visible' => [
        ':input[name="table[' . $this
          ->uuid() . '][form][clientside_resize]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}