Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / dropzonejs / src / Element / DropzoneJs.php
index c4ba01e105e2f01cf934c7d2c78e79aef1ee06ae..ead6be03830f7a669365b02381e21f3fe2e05f09 100644 (file)
@@ -13,22 +13,42 @@ use Drupal\Core\Url;
 /**
  * Provides a DropzoneJS atop of the file element.
  *
- * Configuration options are:
- * - #title
+ * Required options are:
+ * - #title (string)
  *   The main field title.
- * - #description
+ * - #description (string)
  *   Description under the field.
- * - #dropzone_description
+ * - #dropzone_description (string)
  *   Will be visible inside the upload area.
- * - #max_filesize
+ * - #max_filesize (string)
  *   Used by dropzonejs and expressed in number + unit (i.e. 1.1M) This will be
  *   converted to a form that DropzoneJs understands. See:
  *   http://www.dropzonejs.com/#config-maxFilesize
- * - #extensions
+ * - #extensions (string)
  *   A string of valid extensions separated by a space.
- * - #max_files
+ * - #max_files (integer)
  *   Number of files that can be uploaded.
  *   If < 1, there is no limit.
+ * - #clientside_resize (bool)
+ *   Whether or not to use DropzoneJS clientside resizing. It requires v4.4.0+
+ *   version of the library.
+ *
+ * Optional options are:
+ * - #resize_width (integer)
+ *   (optional) The maximum with in px. If omitted defaults to NULL.
+ * - #resize_height (integer)
+ *   (optional) The maximum height in px. If omitted defaults to NULL.
+ * - #resize_quality (float)
+ *   (optional) The quality of the resize. Accepts values from 0 - 1. Ie: 0.8.
+ *   Defautls to 1.
+ * - #resize_method (string)
+ *   (optional) Accepts 'contain', which scales the image, or 'crop' which crops
+ *   the image. Defaults to 'contain'.
+ * - #thumbnail_method (string).
+ *   (optional) Accepts 'contain', which scales the image, or 'crop' which crops
+ *   the image. Defaults to 'contain'.
+ *
+ * @todo Not sure about the version for clientside.
  *
  * When submitted the element returns an array of temporary file locations. It's
  * the duty of the environment that implements this element to handle the
@@ -121,6 +141,17 @@ class DropzoneJs extends FormElement {
       ],
     ];
 
+    if (!empty($element['#clientside_resize'])) {
+      $element['#attached']['drupalSettings']['dropzonejs']['instances'][$element['#id']] += [
+        'resizeWidth' => !empty($element['#resize_width']) ? $element['#resize_width'] : NULL,
+        'resizeHeight' => !empty($element['#resize_height']) ? $element['#resize_height'] : NULL,
+        'resizeQuality' => !empty($element['#resize_quality']) ? $element['#resize_quality'] : 1,
+        'resizeMethod' => !empty($element['#resize_method']) ? $element['#resize_method'] : 'contain',
+        'thumbnailMethod' => !empty($element['#thumbnail_method']) ? $element['#thumbnail_method'] : 'contain',
+      ];
+      array_unshift($element['#attached']['library'], 'dropzonejs/exif-js');
+    }
+
     static::setAttributes($element, ['dropzone-enable']);
     return $element;
   }