Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Commit

Permalink
Issue #2830843 by chr.fritsch, Dimiter: Fixing code style violations
Browse files Browse the repository at this point in the history
  • Loading branch information
chr.fritsch authored and chrfritsch committed Jan 18, 2017
1 parent cbe4f8c commit f377d31
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dropzonejs.module
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [];
Expand Down
8 changes: 3 additions & 5 deletions js/dropzone.integration.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -96,5 +95,4 @@
}
};


}(jQuery, Drupal, drupalSettings));
4 changes: 3 additions & 1 deletion modules/eb_widget/js/dropzonejs_eb_widget.common.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
4 changes: 3 additions & 1 deletion modules/eb_widget/js/dropzonejs_eb_widget.ief_edit.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'],
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/DropzoneJsUploadSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/DropzoneJsUploadSaveInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Element/DropzoneJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Events/DropzoneMediaEntityCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f377d31

Please sign in to comment.