You are here

public function DropzoneJsEbWidget::getForm 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::getForm()
1 call to DropzoneJsEbWidget::getForm()
InlineEntityFormMediaWidget::getForm in modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php
1 method overrides DropzoneJsEbWidget::getForm()
InlineEntityFormMediaWidget::getForm in modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php

File

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

Class

DropzoneJsEbWidget
Provides an Entity Browser widget that uploads new files.

Namespace

Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget

Code

public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
  $form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
  $cardinality = 0;
  $validators = $form_state
    ->get([
    'entity_browser',
    'validators',
  ]);
  if (!empty($validators['cardinality']['cardinality'])) {
    $cardinality = $validators['cardinality']['cardinality'];
  }
  $config = $this
    ->getConfiguration();
  $form['upload'] = [
    '#title' => $this
      ->t('File upload'),
    '#type' => 'dropzonejs',
    '#required' => TRUE,
    '#dropzone_description' => $config['settings']['dropzone_description'],
    '#max_filesize' => $config['settings']['max_filesize'],
    '#extensions' => $config['settings']['extensions'],
    '#max_files' => $cardinality > 0 ? $cardinality : 0,
    '#clientside_resize' => $config['settings']['clientside_resize'],
  ];
  if ($config['settings']['clientside_resize']) {
    $form['upload']['#resize_width'] = $config['settings']['resize_width'];
    $form['upload']['#resize_height'] = $config['settings']['resize_height'];
    $form['upload']['#resize_quality'] = $config['settings']['resize_quality'];
    $form['upload']['#resize_method'] = $config['settings']['resize_method'];
    $form['upload']['#thumbnail_method'] = $config['settings']['thumbnail_method'];
  }
  $form['#attached']['library'][] = 'dropzonejs/widget';

  // Disable the submit button until the upload sucesfully completed.
  $form['#attached']['library'][] = 'dropzonejs_eb_widget/common';
  $original_form['#attributes']['class'][] = 'dropzonejs-disable-submit';

  // Add hidden element used to make execution of auto-select of form.
  if (!empty($config['settings']['auto_select'])) {
    $form['auto_select_handler'] = [
      '#type' => 'hidden',
      '#name' => 'auto_select_handler',
      '#id' => 'auto_select_handler',
      '#attributes' => [
        'id' => 'auto_select_handler',
      ],
      '#submit' => [
        '::submitForm',
      ],
      '#executes_submit_callback' => TRUE,
      '#ajax' => [
        'wrapper' => 'auto_select_handler',
        'callback' => [
          get_class($this),
          'handleAjaxCommand',
        ],
        'event' => 'auto_select_enity_browser_widget',
        'progress' => [
          'type' => 'fullscreen',
        ],
      ],
    ];
  }
  return $form;
}