Commit 163b0a26 authored by chr.fritsch's avatar chr.fritsch Committed by chr.fritsch

Issue #2830843 by chr.fritsch, Dimiter: Fixing code style violations

parent b8c24d79
# Developing
* Pull requests can be made against https://github.com/drupal-media/dropzonejs/pulls
\ No newline at end of file
* Pull requests can be made against https://github.com/drupal-media/dropzonejs/pulls
......@@ -11,16 +11,15 @@ use Drupal\Core\Routing\RouteMatchInterface;
* Implements hook_help().
*/
function dropzonejs_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_name) {
// Main module help for the dropzonejs module.
case 'help.page.dropzonejs':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('DropzoneJS') . '</p>';
return $output;
default:
}
return $output;
}
/**
......
......@@ -7,17 +7,18 @@
*
*/
(function ($, Drupal, drupalSettings) {
"use strict";
'use strict';
Drupal.dropzonejsInstances = [];
/* global Dropzone */
Drupal.behaviors.dropzonejsIntegraion = {
attach: function (context) {
Dropzone.autoDiscover = false;
// @todo Init functionality should support multiple drop zones on page.
var selector = $(".dropzone-enable");
selector.addClass("dropzone");
var selector = $('.dropzone-enable');
selector.addClass('dropzone');
var input = selector.siblings('input');
// Initiate dropzonejs.
......@@ -35,26 +36,26 @@
// If instance exists for configuration, but it's detached from element
// then destroy detached instance and create new instance.
if (instanceConfig.instance !== undefined) {
if (instanceConfig.instance !== void 0) {
instanceConfig.instance.destroy();
}
// Initialize DropzoneJS instance for element.
var dropzoneInstance = new Dropzone("#" + selector.attr("id"), $.extend({}, instanceConfig, config));
var dropzoneInstance = new Dropzone('#' + selector.attr('id'), $.extend({}, instanceConfig, config));
// Other modules might need instances.
drupalSettings["dropzonejs"]["instances"][selector.attr("id")]["instance"] = dropzoneInstance;
drupalSettings['dropzonejs']['instances'][selector.attr('id')]['instance'] = dropzoneInstance;
dropzoneInstance.on("addedfile", function (file) {
dropzoneInstance.on('addedfile', function (file) {
file._removeIcon = Dropzone.createElement("<div class='dropzonejs-remove-icon' title='Remove'></div>");
file.previewElement.appendChild(file._removeIcon);
file._removeIcon.addEventListener("click", function () {
file._removeIcon.addEventListener('click', function () {
dropzoneInstance.removeFile(file);
});
});
// React on add file. Add only accepted files.
dropzoneInstance.on("success", function (file, response) {
dropzoneInstance.on('success', function (file, response) {
var uploadedFilesElement = selector.siblings(':hidden');
var currentValue = uploadedFilesElement.attr('value') || '';
......@@ -66,16 +67,16 @@
});
// React on file removing.
dropzoneInstance.on("removedfile", function (file) {
dropzoneInstance.on('removedfile', function (file) {
var uploadedFilesElement = selector.siblings(':hidden');
var currentValue = uploadedFilesElement.attr('value');
// Remove the file from the element.
if (currentValue.length) {
var fileNames = currentValue.split(";");
var fileNames = currentValue.split(';');
for (var i in fileNames) {
if (fileNames[i] === file.processedName) {
fileNames.splice(i,1);
fileNames.splice(i, 1);
break;
}
}
......@@ -86,7 +87,7 @@
});
// React on maxfilesexceeded. Remove all rejected files.
dropzoneInstance.on("maxfilesexceeded", function () {
dropzoneInstance.on('maxfilesexceeded', function () {
var rejectedFiles = dropzoneInstance.getRejectedFiles();
for (var i = 0; i < rejectedFiles.length; i++) {
dropzoneInstance.removeFile(rejectedFiles[i]);
......
......@@ -21,5 +21,3 @@ multiple files using the DropzoneJS library.
id: dropzonejs
3. The sample content type should be upldated with the new widget.
......@@ -4,30 +4,30 @@
* Bundles various dropzone eb widget behaviours.
*/
(function ($, Drupal, drupalSettings) {
"use strict";
'use strict';
Drupal.behaviors.dropzonejsPostIntegrationEbWidgetCommon = {
attach: function(context) {
if (typeof drupalSettings.dropzonejs.instances !== "undefined") {
attach: function (context) {
if (typeof drupalSettings.dropzonejs.instances !== 'undefined') {
_.each(drupalSettings.dropzonejs.instances, function (item) {
var $form = $(item.instance.element).parents('form');
if ($form.hasClass("dropzonejs-disable-submit")) {
if ($form.hasClass('dropzonejs-disable-submit')) {
var $submit = $form.find('.is-entity-browser-submit');
$submit.prop("disabled", true);
$submit.prop('disabled', true);
item.instance.on("queuecomplete", function () {
if (item.instance.getRejectedFiles().length == 0) {
$submit.prop("disabled", false);
item.instance.on('queuecomplete', function () {
if (item.instance.getRejectedFiles().length === 0) {
$submit.prop('disabled', false);
}
else {
$submit.prop("disabled", true);
$submit.prop('disabled', true);
}
});
item.instance.on("removedfile", function (file) {
if (item.instance.getRejectedFiles().length == 0) {
$submit.removeAttr("disabled");
item.instance.on('removedfile', function () {
if (item.instance.getRejectedFiles().length === 0) {
$submit.removeAttr('disabled');
}
});
}
......
......@@ -4,19 +4,19 @@
* Bundles various dropzone eb widget behaviours.
*/
(function ($, Drupal, drupalSettings) {
"use strict";
'use strict';
Drupal.behaviors.dropzonejsPostIntegrationEbWidgetEditJs = {
attach: function(context) {
if (typeof drupalSettings.dropzonejs.instances !== "undefined") {
attach: function (context) {
if (typeof drupalSettings.dropzonejs.instances !== 'undefined') {
_.each(drupalSettings.dropzonejs.instances, function (item) {
var $form = $(item.instance.element).parents('form');
if ($form.hasClass("dropzonejs-disable-submit")) {
if ($form.hasClass('dropzonejs-disable-submit')) {
var $submit = $form.find('.is-entity-browser-submit');
$submit.prop("disabled", false);
$submit.prop('disabled', false);
var autoSubmitDropzone = function() {
var autoSubmitDropzone = function () {
var $form = this;
// Trigger generation of IEF form only, when there are new
......@@ -28,11 +28,11 @@
}
}.bind($form);
item.instance.on("queuecomplete", function() {
item.instance.on('queuecomplete', function () {
autoSubmitDropzone();
});
item.instance.on("removedfile", function() {
item.instance.on('removedfile', function () {
autoSubmitDropzone();
});
}
......
......@@ -11,7 +11,6 @@ use Drupal\Core\Utility\Token;
use Drupal\dropzonejs\DropzoneJsUploadSaveInterface;
use Drupal\entity_browser\WidgetBase;
use Drupal\entity_browser\WidgetValidationManager;
use Drupal\file\Entity\File;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
......
......@@ -2,7 +2,6 @@
namespace Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent;
......@@ -99,6 +98,7 @@ class InlineEntityFormMediaWidget extends MediaEntityDropzoneJsEbWidget {
$media_entities = $this->prepareEntities($form, $form_state);
$source_field = $this->getBundle()->getTypeConfiguration()['source_field'];
foreach ($media_entities as $media_entity) {
/** @var \Drupal\file\Entity\File $file */
$file = $media_entity->$source_field->entity;
$file->save();
$media_entity->$source_field->target_id = $file->id();
......@@ -142,7 +142,7 @@ class InlineEntityFormMediaWidget extends MediaEntityDropzoneJsEbWidget {
protected function prepareEntitiesFromForm($form, FormStateInterface $form_state) {
$media_entities = [];
foreach (Element::children($form['widget']['entities']) as $key) {
/** @var ContentEntityInterface $entity */
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $form['widget']['entities'][$key]['#entity'];
$inline_entity_form_handler = InlineEntityForm::getInlineFormHandler($entity->getEntityTypeId());
$inline_entity_form_handler->entityFormSubmit($form['widget']['entities'][$key], $form_state);
......
......@@ -55,6 +55,8 @@ class MediaEntityDropzoneJsEbWidget extends DropzoneJsEbWidget {
* The upload saving dropzonejs service.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user service.
* @param Token $token
* The token service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
......@@ -181,6 +183,7 @@ class MediaEntityDropzoneJsEbWidget extends DropzoneJsEbWidget {
foreach ($media_entities as &$media_entity) {
$file = $media_entity->$source_field->entity;
/** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */
$event = $this->eventDispatcher->dispatch(Events::MEDIA_ENTITY_CREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $element));
$media_entity = $event->getMediaEntity();
// If we don't save file at this point Media entity creates another file
......
......@@ -26,7 +26,7 @@ class UploadController extends ControllerBase {
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request $request
* @var \Symfony\Component\HttpFoundation\Request
* The HTTP request object.
*/
protected $request;
......@@ -34,12 +34,10 @@ class UploadController extends ControllerBase {
/**
* Constructs dropzone upload controller route controller.
*
* @param \Drupal\dropzonejs\UploadHandlerInterface $upload_handler
* Upload handler.
* @param \Symfony\Component\HttpFoundation\Request $request
* Request object.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* Config factory.
* @param \Drupal\Core\Transliteration\PhpTransliteration $transliteration
* Transliteration service.
*/
public function __construct(UploadHandlerInterface $upload_handler, Request $request) {
$this->uploadHandler = $upload_handler;
......
......@@ -31,14 +31,14 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
/**
* Mime type guesser service.
*
* @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
* @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface
*/
protected $mimeTypeGuesser;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface;
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
......
......@@ -56,7 +56,7 @@ class DropzoneJs extends FormElement {
'#theme_wrappers' => ['form_element'],
'#tree' => TRUE,
'#attached' => [
'library' => ['dropzonejs/integration']
'library' => ['dropzonejs/integration'],
],
];
}
......@@ -87,7 +87,7 @@ class DropzoneJs extends FormElement {
if (!\Drupal::currentUser()->hasPermission('dropzone upload files')) {
$element['#access'] = FALSE;
drupal_set_message("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator", 'warning');
drupal_set_message(t("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator"), 'warning');
}
return $element;
......@@ -129,8 +129,7 @@ class DropzoneJs extends FormElement {
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
$file_names = [];
$return['uploaded_files'] = NULL;
$return['uploaded_files'] = [];
if ($input !== FALSE) {
$user_input = NestedArray::getValue($form_state->getUserInput(), $element['#parents'] + ['uploaded_files']);
......@@ -171,9 +170,8 @@ class DropzoneJs extends FormElement {
}
}
$form_state->setValueForElement($element, $return);
return $return;
}
return $return;
}
/**
......@@ -206,4 +204,5 @@ class DropzoneJs extends FormElement {
array_pop($parts);
return implode('.', $parts);
}
}
......@@ -54,11 +54,11 @@ class DropzoneMediaEntityCreateEvent extends Event {
* The media entity being created.
* @param \Drupal\file\FileInterface $file
* The file that will be used for the media entity.
* @param $form
* @param array $form
* The form that contains the Dropzone element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
* @param $element
* @param array $element
* The Dropzone form element.
*/
public function __construct(MediaInterface $media_entity, FileInterface $file, $form, FormStateInterface $form_state, $element) {
......@@ -73,6 +73,7 @@ class DropzoneMediaEntityCreateEvent extends Event {
* Get the media entity.
*
* @return \Drupal\media_entity\MediaInterface
* A media entity.
*/
public function getMediaEntity() {
return $this->mediaEntity;
......@@ -92,6 +93,7 @@ class DropzoneMediaEntityCreateEvent extends Event {
* Get the file for the media entity.
*
* @return \Drupal\file\FileInterface
* The file that will be used for the media entity.
*/
public function getFile() {
return $this->file;
......@@ -101,6 +103,7 @@ class DropzoneMediaEntityCreateEvent extends Event {
* Get the form that contains the Dropzone element.
*
* @return array
* The form that contains the Dropzone element.
*/
public function getForm() {
return $this->form;
......@@ -110,6 +113,7 @@ class DropzoneMediaEntityCreateEvent extends Event {
* Get the form state.
*
* @return \Drupal\Core\Form\FormStateInterface
* The current formstate.
*/
public function getFormState() {
return $this->formState;
......@@ -129,6 +133,7 @@ class DropzoneMediaEntityCreateEvent extends Event {
* Get the Dropzone form element.
*
* @return array
* The dropzone element.
*/
public function getElement() {
return $this->element;
......@@ -137,7 +142,7 @@ class DropzoneMediaEntityCreateEvent extends Event {
/**
* Set the Dropzone form element.
*
* @param $element
* @param array $element
* The updated form element.
*/
public function setElement($element) {
......
......@@ -8,6 +8,8 @@ namespace Drupal\dropzonejs\Events;
final class Events {
/**
* The MEDIA_ENTITY_CREATE event.
*
* The MEDIA_ENTITY_CREATE event occurs when creating a new Media Entity,
* before it is saved to the database.
*
......
......@@ -4,6 +4,9 @@ namespace Drupal\dropzonejs;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Class UploadException.
*/
class UploadException extends \Exception {
/**
......@@ -39,7 +42,7 @@ class UploadException extends \Exception {
/**
* Code to error message mapping.
*
* @param array $code
* @var array
*/
public $errorMessages = array(
self::INPUT_ERROR => 'Failed to open input stream.',
......
......@@ -20,7 +20,7 @@ class UploadHandler implements UploadHandlerInterface {
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request $request
* @var \Symfony\Component\HttpFoundation\Request
* The HTTP request object.
*/
protected $request;
......
......@@ -4,6 +4,9 @@ namespace Drupal\dropzonejs;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Interface UploadHandlerInterface.
*/
interface UploadHandlerInterface {
/**
......
<?php
namespace Drupal\dropzonejs_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class DropzoneJsTestForm.
*/
class DropzoneJsTestForm extends FormBase {
/**
......@@ -18,7 +22,7 @@ class DropzoneJsTestForm extends FormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['dropzonejs'] = [
'#title' => t('DropzoneJs element'),
'#title' => $this->t('DropzoneJs element'),
'#type' => 'dropzonejs',
'#required' => TRUE,
'#dropzone_description' => 'DropzoneJs description',
......
......@@ -18,7 +18,13 @@ class DropzoneJsElementTest extends KernelTestBase {
*
* @var array
*/
public static $modules = ['system', 'file', 'user', 'dropzonejs', 'dropzonejs_test'];
public static $modules = [
'system',
'file',
'user',
'dropzonejs',
'dropzonejs_test',
];
/**
* {@inheritdoc}
......@@ -56,4 +62,5 @@ class DropzoneJsElementTest extends KernelTestBase {
$this->assertTrue($this->xpath("/html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]"));
$this->assertTrue($this->xpath("/html/body/script[contains(@src, 'modules/contrib/dropzonejs/js/dropzone.integration.js')]"));
}
}
......@@ -93,4 +93,5 @@ class DropzoneJsUploadControllerTest extends KernelTestBase {
$this->assertTrue(file_exists($result_file));
$this->assertEquals(file_get_contents($result_file), $this->testfileData);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment