Skip to content

Commit

Permalink
Merge pull request #5 from BurdaMagazinOrg/feature/eb_widget
Browse files Browse the repository at this point in the history
Looks good. Follow Up Tickets DRPLDCX-55 and DRPLDCX-56 are in place. 
Merging.
  • Loading branch information
goechsler committed Apr 26, 2016
2 parents f6e176a + 46ed6aa commit 3e9fb17
Show file tree
Hide file tree
Showing 18 changed files with 319 additions and 137 deletions.
34 changes: 34 additions & 0 deletions modules/dcx_dropzone_ui/css/dcx-dropzone-ui.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.dcx-dropzone {
width: 100%;
text-align: center;
margin: 1em 0;
padding: 1em;
height: 300px;
background-color: white;
outline: 2px dashed #0074bd;
outline-offset: -10px;
color: #004f80;
}

.dcx-dropzone.is-dragover {
background-color: #6b6b6b;
}

.box__dragndrop,
.box__uploading,
.box__success,
.box__error {
display: none;
}

.box__input {
position: relative;
top: 50%;
}

.dcx-dropzone.is-uploading .box__input {
display: none;
}
.dcx-dropzone.is-uploading .box__uploading {
display: block;
}
10 changes: 10 additions & 0 deletions modules/dcx_dropzone_ui/dcx_dropzone_ui.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: DC-X Dropzone UI
type: module
description: 'Dropzone Element for DCX DnD'

version: '0'
core: '8.x'
package: dcx

dependencies:
- dcx_migration
7 changes: 7 additions & 0 deletions modules/dcx_dropzone_ui/dcx_dropzone_ui.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dropzone:
version: 0
js:
js/dcx-dropzone-ui.js: {}
css:
theme:
css/dcx-dropzone-ui.css: {}
41 changes: 41 additions & 0 deletions modules/dcx_dropzone_ui/dcx_dropzone_ui.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

function dcx_dropzone_ui_theme() {
return [
'dcxdropzone' => [
'render element' => 'element',
],
];
}

/**
* Prepares variables for dropzone form element.
*
* Default template: dcxdropzone.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: A render element representing the file.
*/
function template_preprocess_dcxdropzone(&$variables) {
$element = $variables['element'];

$variables['attributes'] = [];
if (isset($element['#id'])) {
$variables['attributes']['id'] = $element['#id'];
}
if (!empty($element['#attributes']['class'])) {
$variables['attributes']['class'] = (array) $element['#attributes']['class'];
}

$variables['attributes']['class'][] = 'dcx-dropzone';

if (isset($element['#dropzone_description'])) {
$variables['description'] = $element['#dropzone_description'];
}
else {
$variables['description'] = 'DC-X Dropzone';
}

$variables['dropvalue'] = $element['dropvalue'];
}
45 changes: 45 additions & 0 deletions modules/dcx_dropzone_ui/js/dcx-dropzone-ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(function ($, Drupal, drupalSettings) {
"use strict";

Drupal.behaviors.dcxDropzoneUi = {
attach: function (context, settings) {

var dropzone_id = drupalSettings.dcx_dropzone.dropzone_id,
dropzone = $('#' + dropzone_id);

dropzone.on('dragover dragenter', function (event) {
event.preventDefault();
dropzone.addClass('is-dragover');
});

dropzone.on('dragleave dragend drop', function (event) {
event.preventDefault();
dropzone.removeClass('is-dragover');
});

dropzone.on('drop', function (event) {
event.preventDefault();

if (dropzone.hasClass('is-uploading')) return false;

dropzone.addClass('is-uploading').removeClass('is-error');


var uri = decodeURIComponent(event.originalEvent.dataTransfer.getData('text/uri-list'));
var data = uri.split('?')[0];
data = [{'documenttype-image': data.substr(data.indexOf('document'))}];

$.ajax({
url: "/dcx-migration/upload",
method: 'POST',
data: JSON.stringify(data)
}).complete(function() {
dropzone.removeClass('is-uploading');
}).success(function(data) {
dropzone.addClass( data.success == true ? 'is-success' : 'is-error' );
});
});
}
};

})(jQuery, Drupal, drupalSettings);
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,63 @@

/**
* @file
* Contains \Drupal\dcx_migration\Form\DcxImportForm.
* Contains \Drupal\dcx_dropzone_ui\Controller\UploadController.
*/

namespace Drupal\dcx_migration\Form;
namespace Drupal\dcx_dropzone_ui\Controller;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\dcx_migration\DcxImportServiceInterface;
use Drupal\dcx_migration\Exception\AlreadyMigratedException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* Class DcxImportForm.
*
* @package Drupal\dcx_migration\Form
* Handles requests that dcx dropzone issues when uploading files.
*/
class DcxImportForm extends FormBase {
class UploadController extends ControllerBase {

protected $importService;

/**
* Constructor.
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request $request
* The HTTP request object.
*/
protected $request;

/**
* Constructs dropzone upload controller route controller.
*
* @param \Drupal\dcx_migration\DcxImportServiceInterface $importService
* The DCX Import Service actually processing the input.
* @param \Symfony\Component\HttpFoundation\Request $request
* Request object.
*/
public function __construct(DcxImportServiceInterface $importService) {
public function __construct(DcxImportServiceInterface $importService, Request $request) {
$this->importService = $importService;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('dcx_migration.import'));
$this->request = $request;
}


/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dcx_import_form';
public static function create(ContainerInterface $container) {
return new static(
$container->get('dcx_migration.import'),
$container->get('request_stack')->getCurrentRequest()
);
}

/**
* {@inheritdoc}
* Handles Dcx Dropzone uploads.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['dropzone'] = [
'#title' => t('DC-X Dropzone element'),
'#dropzone_description' => 'Custom description goes here.',
'#type' => 'dcxdropzone',
];

return $form;
}
public function handleUploads() {

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$data = $form_state->getValue('dropzone');
$data = $this->request->getContent();

$ids = [];
// Data might be a simple string, which is technically not JSON ... so
Expand All @@ -85,10 +79,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}

if (empty($ids)) {
return;
throw new NotFoundHttpException();
}

$this->importService->import($ids);
}

return new JsonResponse([], 200);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Drupal\dcx_migration\Element;
namespace Drupal\dcx_dropzone_ui\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\FormElement;
Expand All @@ -26,7 +26,7 @@ public function getInfo() {
'#theme' => 'dcxdropzone',
'#theme_wrappers' => ['form_element'],
'#attached' => [
'library' => ['dcx_migration/dropzone']
'library' => ['dcx_dropzone_ui/dropzone']
],
'#tree' => TRUE,
];
Expand Down
14 changes: 14 additions & 0 deletions modules/dcx_dropzone_ui/templates/dcxdropzone.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div{{ attributes }}>

<div class="box__input">

{{description}}
</div>

<div class="box__uploading">Uploading&hellip;</div>
<div class="box__success">Done!</div>
<div class="box__error">Error! <span></span>.</div>
</div>
{{ dropvalue }}


11 changes: 11 additions & 0 deletions modules/dcx_entity_browser/dcx_entity_browser.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: DC-X Entity Browser
type: module
description: 'Entity Browser integration for dcx'

version: '0'
core: '8.x'
package: dcx

dependencies:
- dcx_dropzone_ui
- entity_browser
11 changes: 11 additions & 0 deletions modules/dcx_entity_browser/dcx_entity_browser.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* @param $form
*/
function dcx_entity_browser_form_entity_browser_media_entity_browser_form_alter(&$form) {

if (!empty($form['widget']['dropzone']['#type']) && $form['widget']['dropzone']['#type'] == 'dcxdropzone') {
$form['actions'] = [];
}
}
Loading

0 comments on commit 3e9fb17

Please sign in to comment.