Commit fd61719e authored by slashrsm's avatar slashrsm
Browse files

Merge pull request #2 from primsi/bugfixes_01

by primsi: various bugfixes
parents 3bac3715 721e5175
......@@ -85,6 +85,14 @@ class UploadController extends ControllerBase {
catch (UploadException $e) {
return $e->getErrorResponse();
}
// Return JSON-RPC response.
// Controllers should return a response.
return new JsonResponse([
'jsonrpc' => '2.0',
'result' => NULL,
'id' => 'id',
], 200);
}
/**
......@@ -144,7 +152,7 @@ class UploadController extends ControllerBase {
}
// Open temp file.
$tmp = $this->temporaryUploadLocation . $this->getFilename($file);
$tmp = "{$this->temporaryUploadLocation}/{$this->getFilename($file)}";
if (!($out = fopen("{$this->temporaryUploadLocation}/{$this->getFilename($file)}", $this->request->request->get('chunk', 0) ? 'ab' : 'wb'))) {
throw new UploadException(UploadException::OUTPUT_ERROR);
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\dropzonejs\Element;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\FormElement;
......@@ -25,8 +26,9 @@ use Drupal\Core\Render\Element\FormElement;
* Used by dropzonejs and expressed in MB. See
* http://www.dropzonejs.com/#config-maxFilesize
*
*
* @todo Remove updated_files from the values array.
* When submitted the element returns an array of temporary file locations. It's
* the duty of the environment that implements this element to handle the
* uploaded files.
*
* @FormElement("dropzonejs")
*/
......@@ -94,17 +96,17 @@ class DropzoneJs extends FormElement {
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
$file_names = [];
$return = NULL;
$return['uploaded_files'] = NULL;
if ($input !== FALSE) {
$user_input = $form_state->getUserInput();
$user_input = NestedArray::getValue($form_state->getUserInput(), $element['#parents'], $key_exists);
if (!empty($user_input['uploaded_files'])) {
$file_names = array_filter(explode(';', $user_input['uploaded_files']));
$temp_path = \Drupal::config('system.file')->get('path.temporary');
foreach ($file_names as $name) {
$return[] = "$temp_path/$name";
$return['uploaded_files'][] = "$temp_path/$name";
}
}
$form_state->setValueForElement($element, $return);
......
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