X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdropzonejs%2Fmodules%2Feb_widget%2Fsrc%2FPlugin%2FEntityBrowser%2FWidget%2FDropzoneJsEbWidget.php;fp=web%2Fmodules%2Fcontrib%2Fdropzonejs%2Fmodules%2Feb_widget%2Fsrc%2FPlugin%2FEntityBrowser%2FWidget%2FDropzoneJsEbWidget.php;h=a12d95524558b2897b2e30cf78e6f15f5f3fdace;hp=242e68124b1cf274fcac12fa238a2ebae6ae152a;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/modules/contrib/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php b/web/modules/contrib/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php index 242e68124..a12d95524 100644 --- a/web/modules/contrib/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php +++ b/web/modules/contrib/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php @@ -104,6 +104,12 @@ class DropzoneJsEbWidget extends WidgetBase { 'dropzone_description' => $this->t('Drop files here to upload them'), 'max_filesize' => file_upload_max_size() / pow(Bytes::KILOBYTE, 2) . 'M', 'extensions' => 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', + 'clientside_resize' => FALSE, + 'resize_width' => NULL, + 'resize_height' => NULL, + 'resize_quality' => 1, + 'resize_method' => 'contain', + 'thumbnail_method' => 'contain', ] + parent::defaultConfiguration(); } @@ -127,8 +133,17 @@ class DropzoneJsEbWidget extends WidgetBase { '#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'; @@ -360,6 +375,107 @@ class DropzoneJsEbWidget extends WidgetBase { '#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 exif 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; }