diff --git a/dropzonejs.module b/dropzonejs.module index 26127d1..f79d578 100644 --- a/dropzonejs.module +++ b/dropzonejs.module @@ -42,7 +42,7 @@ function dropzonejs_theme() { * An associative array containing: * - element: A render element representing the file. */ -function template_preprocess_dropzonejs(&$variables) { +function template_preprocess_dropzonejs(array &$variables) { $element = $variables['element']; $variables['attributes'] = []; diff --git a/js/dropzone.integration.js b/js/dropzone.integration.js index 518cabf..38fd252 100644 --- a/js/dropzone.integration.js +++ b/js/dropzone.integration.js @@ -1,11 +1,10 @@ /** - * @file dropzone.integration.js + * @file + * dropzone.integration.js * * Defines the behaviors needed for dropzonejs integration. - * - * @todo Implement maxfilesexceeded. - * */ + (function ($, Drupal, drupalSettings) { 'use strict'; @@ -96,5 +95,4 @@ } }; - }(jQuery, Drupal, drupalSettings)); diff --git a/modules/eb_widget/js/dropzonejs_eb_widget.common.js b/modules/eb_widget/js/dropzonejs_eb_widget.common.js index 5c8bf92..1149953 100644 --- a/modules/eb_widget/js/dropzonejs_eb_widget.common.js +++ b/modules/eb_widget/js/dropzonejs_eb_widget.common.js @@ -1,8 +1,10 @@ /** - * @file dropzonejs_eb_widget.common.js + * @file + * dropzonejs_eb_widget.common.js * * Bundles various dropzone eb widget behaviours. */ + (function ($, Drupal, drupalSettings) { 'use strict'; diff --git a/modules/eb_widget/js/dropzonejs_eb_widget.ief_edit.js b/modules/eb_widget/js/dropzonejs_eb_widget.ief_edit.js index 7a1ee7e..7ae974b 100644 --- a/modules/eb_widget/js/dropzonejs_eb_widget.ief_edit.js +++ b/modules/eb_widget/js/dropzonejs_eb_widget.ief_edit.js @@ -1,8 +1,10 @@ /** - * @file dropzonejs_eb_widget.common.js + * @file + * dropzonejs_eb_widget.ief_edit.js * * Bundles various dropzone eb widget behaviours. */ + (function ($, Drupal, drupalSettings) { 'use strict'; diff --git a/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php index 0572d15..ed68a17 100644 --- a/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php +++ b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php @@ -98,7 +98,7 @@ public static function create(ContainerInterface $container, array $configuratio public function defaultConfiguration() { return [ 'upload_location' => 'public://[date:custom:Y]-[date:custom:m]', - 'dropzone_description' => t('Drop files here to upload them'), + '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', ] + parent::defaultConfiguration(); @@ -117,7 +117,7 @@ public function getForm(array &$original_form, FormStateInterface $form_state, a } $config = $this->getConfiguration(); $form['upload'] = [ - '#title' => t('File upload'), + '#title' => $this->t('File upload'), '#type' => 'dropzonejs', '#required' => TRUE, '#dropzone_description' => $config['settings']['dropzone_description'], @@ -206,17 +206,17 @@ public function validate(array &$form, FormStateInterface $form_state) { if ($trigger['#type'] == 'submit' && $trigger['#name'] == 'op') { $upload_location = $this->getUploadLocation(); if (!file_prepare_directory($upload_location, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { - $form_state->setError($form['widget']['upload'], t('Files could not be uploaded because the destination directory %destination is not configured correctly.', ['%destination' => $this->getConfiguration()['settings']['upload_location']])); + $form_state->setError($form['widget']['upload'], $this->t('Files could not be uploaded because the destination directory %destination is not configured correctly.', ['%destination' => $this->getConfiguration()['settings']['upload_location']])); } $files = $this->getFiles($form, $form_state); if (in_array(FALSE, $files)) { // @todo Output the actual errors from validateFile. - $form_state->setError($form['widget']['upload'], t('Some files that you are trying to upload did not pass validation. Requirements are: max file %size, allowed extensions are %extensions', ['%size' => $this->getConfiguration()['settings']['max_filesize'], '%extensions' => $this->getConfiguration()['settings']['extensions']])); + $form_state->setError($form['widget']['upload'], $this->t('Some files that you are trying to upload did not pass validation. Requirements are: max file %size, allowed extensions are %extensions', ['%size' => $this->getConfiguration()['settings']['max_filesize'], '%extensions' => $this->getConfiguration()['settings']['extensions']])); } if (empty($files)) { - $form_state->setError($form['widget']['upload'], t('At least one valid file should be uploaded.')); + $form_state->setError($form['widget']['upload'], $this->t('At least one valid file should be uploaded.')); } // If there weren't any errors set, run the normal validators. diff --git a/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php index 3b2ecbc..083d1f9 100644 --- a/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php +++ b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php @@ -139,7 +139,7 @@ public function validate(array &$form, FormStateInterface $form_state) { * @return \Drupal\media_entity\MediaInterface[] * The prepared media entities. */ - protected function prepareEntitiesFromForm($form, FormStateInterface $form_state) { + protected function prepareEntitiesFromForm(array $form, FormStateInterface $form_state) { $media_entities = []; foreach (Element::children($form['widget']['entities']) as $key) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ diff --git a/src/DropzoneJsUploadSave.php b/src/DropzoneJsUploadSave.php index 8d72b19..cd0d188 100644 --- a/src/DropzoneJsUploadSave.php +++ b/src/DropzoneJsUploadSave.php @@ -101,7 +101,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Mim /** * {@inheritdoc} */ - public function createFile($uri, $destination, $extensions, AccountProxyInterface $user, $validators = []) { + public function createFile($uri, $destination, $extensions, AccountProxyInterface $user, array $validators = []) { // Create the file entity. $uri = file_stream_wrapper_uri_normalize($uri); $file_info = new \SplFileInfo($uri); diff --git a/src/DropzoneJsUploadSaveInterface.php b/src/DropzoneJsUploadSaveInterface.php index f349439..9d5672c 100644 --- a/src/DropzoneJsUploadSaveInterface.php +++ b/src/DropzoneJsUploadSaveInterface.php @@ -35,14 +35,14 @@ interface DropzoneJsUploadSaveInterface { * The file entity of the newly uploaded file or false in case of a failure. * The file isn't saved yet. That should be handled by the caller. */ - public function createFile($uri, $destination, $extensions, AccountProxyInterface $user, $validators = []); + public function createFile($uri, $destination, $extensions, AccountProxyInterface $user, array $validators = []); /** * Validate the uploaded file. * * @param \Drupal\file\FileInterface $file * The file entity object. - * @param array $extensions + * @param string $extensions * A space separated string of valid extensions. * @param array $additional_validators * An optional, associative array of callback functions used to validate the diff --git a/src/Element/DropzoneJs.php b/src/Element/DropzoneJs.php index ae05c1f..ba48de5 100644 --- a/src/Element/DropzoneJs.php +++ b/src/Element/DropzoneJs.php @@ -104,7 +104,7 @@ public static function processDropzoneJs(&$element, FormStateInterface $form_sta * @return array * The $element with prepared variables ready for input.html.twig. */ - public static function preRenderDropzoneJs($element) { + public static function preRenderDropzoneJs(array $element) { // Convert the human size input to bytes, convert it to MB and round it. $max_size = round(Bytes::toInt($element['#max_filesize']) / pow(Bytes::KILOBYTE, 2), 2); @@ -183,7 +183,7 @@ public static function valueCallback(&$element, $input, FormStateInterface $form * @return string * A space separated list of extensions. */ - public static function getValidExtensions($element) { + public static function getValidExtensions(array $element) { return isset($element['#extensions']) ? $element['#extensions'] : self::DEFAULT_VALID_EXTENSIONS; } diff --git a/src/Events/DropzoneMediaEntityCreateEvent.php b/src/Events/DropzoneMediaEntityCreateEvent.php index a325504..dd545d9 100644 --- a/src/Events/DropzoneMediaEntityCreateEvent.php +++ b/src/Events/DropzoneMediaEntityCreateEvent.php @@ -61,7 +61,7 @@ class DropzoneMediaEntityCreateEvent extends Event { * @param array $element * The Dropzone form element. */ - public function __construct(MediaInterface $media_entity, FileInterface $file, $form, FormStateInterface $form_state, $element) { + public function __construct(MediaInterface $media_entity, FileInterface $file, array $form, FormStateInterface $form_state, array $element) { $this->mediaEntity = $media_entity; $this->file = $file; $this->form = $form; @@ -145,7 +145,7 @@ public function getElement() { * @param array $element * The updated form element. */ - public function setElement($element) { + public function setElement(array $element) { $this->element = $element; }