-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move DnD widget in a EntityBrowser Widget #5
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
<?php | ||
|
||
function dcx_integration_form_dcx_import_form_alter(&$form) { | ||
$form['draggables'] = [ | ||
'#theme' => 'item_list', | ||
'#title' => 'Draggables for testing provided by dcx_integration_debug module.', | ||
'#items' => [ | ||
['#markup' => '<div class="item single">Single image</div>'], | ||
['#markup' => '<div class="item list">List of images</div>'], | ||
], | ||
'#attributes' => ['class' => 'draggable'] | ||
]; | ||
function dcx_integration_debug_form_entity_browser_media_entity_browser_form_alter(&$form) { | ||
|
||
if (!empty($form['widget']['dropzone']['#type']) && $form['widget']['dropzone']['#type'] == 'dcxdropzone') { | ||
$form['draggables'] = [ | ||
'#theme' => 'item_list', | ||
'#title' => 'Draggables for testing provided by dcx_integration_debug module.', | ||
'#items' => [ | ||
['#markup' => '<div class="item single">Single image</div>'], | ||
['#markup' => '<div class="item list">List of images</div>'], | ||
], | ||
'#attributes' => ['class' => 'draggable'] | ||
]; | ||
|
||
$form['#attached']['library'][] = 'dcx_integration_debug/draggable'; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
dcx_migration.import: | ||
path: 'dcx-migration/import' | ||
dcx_migration.upload: | ||
path: '/dcx-migration/upload' | ||
defaults: | ||
_form: '\Drupal\dcx_migration\Form\DcxImportForm' | ||
_title: 'Import from DC-X' | ||
_controller: '\Drupal\dcx_migration\Controller\UploadController::handleUploads' | ||
requirements: | ||
_permission: 'import from dcx' | ||
_permission: 'dcx import' | ||
_method: 'POST' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\dropzonejs\Controller\UploadController. | ||
*/ | ||
|
||
namespace Drupal\dcx_migration\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\dcx_migration\DcxImportServiceInterface; | ||
use Drupal\dropzonejs\UploadException; | ||
use Drupal\dropzonejs\UploadHandlerInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
|
||
/** | ||
* Handles requests that dropzone issues when uploading files. | ||
*/ | ||
class UploadController extends ControllerBase { | ||
|
||
protected $importService; | ||
|
||
/** | ||
* 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, Request $request) { | ||
$this->importService = $importService; | ||
|
||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('dcx_migration.import'), | ||
$container->get('request_stack')->getCurrentRequest() | ||
); | ||
} | ||
|
||
/** | ||
* Handles DropzoneJs uploads. | ||
*/ | ||
public function handleUploads() { | ||
|
||
$data = $this->request->getContent(); | ||
|
||
$ids = []; | ||
// Data might be a simple string, which is technically not JSON ... so | ||
// we need to check | ||
$json = json_decode($data); | ||
|
||
if ($json === NULL) { // decoding failed -> single item URL as string | ||
preg_match('|dcx/(document/doc.*)\?|', $data, $matches); | ||
if (!empty($matches)) { | ||
$ids[] = "dcxapi:" . $matches[1]; | ||
} | ||
} | ||
else { // decoding was successfull -> data is JSON -> data is multiple ids | ||
$data = $json; | ||
foreach($data as $val) { | ||
$ids[] = "dcxapi:" . current($val); | ||
} | ||
} | ||
|
||
if (empty($ids)) { | ||
return new JsonResponse([], 404); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, but NotFoundHttpException should return JSON if the accept headers ask for it. Do we need an empty json list here, when 404? |
||
} | ||
|
||
$this->importService->import($ids); | ||
|
||
return new JsonResponse([], 200); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: Do we need an empty json list here, when 200? Technically 204 is the right code here. "All fine, but no response given." |
||
|
||
|
||
} | ||
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh. Nitpick!