From e853b6de9e91f0e0ca04b202e8adfc9a4ec18d54 Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Sun, 24 Jun 2018 18:47:40 +0700 Subject: [PATCH 01/13] UPGRADE: Ran upgrader tool --- _config/config.yml | 19 +++++++--- code/DropzoneFile.php | 6 +++ code/FileAttachmentField.php | 53 ++++++++++++++++++++++----- code/FileAttachmentFieldCleanTask.php | 3 ++ code/FileAttachmentFieldTrack.php | 7 +++- 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index 0836b50..6327aa7 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -3,8 +3,14 @@ Name: dropzone After: 'framework/*','cms/*' --- FileAttachmentField: - default_config_path: 'javascript/default_config.json' - icon_sizes: [16, 32, 48, 64, 128, 512] + default_config_path: javascript/default_config.json + icon_sizes: + - 16 + - 32 + - 48 + - 64 + - 128 + - 512 upgrade_images: true list_thumbnail_width: 64 list_thumbnail_height: 64 @@ -17,9 +23,10 @@ FileAttachmentField: param_name: file create_image_thumbnails: true max_thumbnail_filesize: 10 - clickable: '.dropzone-select' + clickable: .dropzone-select auto_process_queue: true auto_queue: true - add_remove_links: false -File: - extensions: [DropzoneFile] \ No newline at end of file + add_remove_links: false +SilverStripe\Assets\File: + extensions: + - DropzoneFile diff --git a/code/DropzoneFile.php b/code/DropzoneFile.php index 24d5e7f..9648c47 100644 --- a/code/DropzoneFile.php +++ b/code/DropzoneFile.php @@ -1,5 +1,11 @@ permissions['upload'] = true; $this->permissions['detach'] = true; $this->permissions['delete'] = function () use ($instance) { - return Injector::inst()->get('File')->canDelete() && $instance->isCMS(); + return Injector::inst()->get(File::class)->canDelete() && $instance->isCMS(); }; $this->permissions['attach'] = function () use ($instance) { return $instance->isCMS(); @@ -788,7 +821,7 @@ private function getUploadUserError($code) { * @return SS_HTTPResponse * @return SS_HTTPResponse */ - public function upload(SS_HTTPRequest $request) { + public function upload(HTTPRequest $request) { $name = $this->getSetting('paramName'); $files = (!empty($_FILES[$name]) ? $_FILES[$name] : array()); @@ -867,7 +900,7 @@ public function upload(SS_HTTPRequest $request) { if (!$formController instanceof LeftAndMain) { $trackFile->setRecord($formController->getRecord()); } - } else if ($formClass !== 'Form') { + } else if ($formClass !== Form::class) { $trackFile->ControllerClass = $formClass; } else { // If using generic 'Form' instance, get controller @@ -879,7 +912,7 @@ public function upload(SS_HTTPRequest $request) { } $this->addValidFileIDs($ids); - return new SS_HTTPResponse(implode(',', $ids), 200); + return new HTTPResponse(implode(',', $ids), 200); } @@ -887,7 +920,7 @@ public function upload(SS_HTTPRequest $request) { * @param SS_HTTPRequest $request * @return UploadField_ItemHandler */ - public function handleSelect(SS_HTTPRequest $request) { + public function handleSelect(HTTPRequest $request) { if($this->isDisabled() || $this->isReadonly() || !$this->CanAttach()) { return $this->httpError(403); } @@ -1142,15 +1175,15 @@ public function getFileClass($filename = null) { if($record) { $class = $record->getRelationClass($name); - if(!$class) $class = "File"; + if(!$class) $class = File::class; } if($filename) { - if($defaultClass == "Image" && + if($defaultClass == Image::class && $this->config()->upgrade_images && !Injector::inst()->get($class) instanceof Image ) { - $class = "Image"; + $class = Image::class; } } @@ -1312,7 +1345,7 @@ class FileAttachmentField_SelectHandler extends UploadField_SelectHandler { */ protected function getListField($folderID) { // Generate the folder selection field. - $folderField = new TreeDropdownField('ParentID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'); + $folderField = new TreeDropdownField('ParentID', _t('HtmlEditorField.FOLDER', Folder::class), Folder::class); $folderField->setValue($folderID); // Generate the file list field. @@ -1348,7 +1381,7 @@ protected function getListField($folderID) { } - public function filesbyid(SS_HTTPRequest $r) { + public function filesbyid(HTTPRequest $r) { $ids = $r->getVar('ids'); $files = File::get()->byIDs(explode(',',$ids)); diff --git a/code/FileAttachmentFieldCleanTask.php b/code/FileAttachmentFieldCleanTask.php index df6983a..6511000 100644 --- a/code/FileAttachmentFieldCleanTask.php +++ b/code/FileAttachmentFieldCleanTask.php @@ -1,5 +1,8 @@ 'File', + 'File' => File::class, ); public static function untrack($fileIDs) { From fa2a2364dbd7f22a26afcd068f50f3b5a8be866b Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Sun, 24 Jun 2018 21:15:53 +0700 Subject: [PATCH 02/13] FIX: Namespaces --- code/DropzoneFile.php | 4 +++- code/FileAttachmentField.php | 1 + code/FileAttachmentFieldCleanTask.php | 1 + code/FileAttachmentFieldTrack.php | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/code/DropzoneFile.php b/code/DropzoneFile.php index 9648c47..7ebc5e0 100644 --- a/code/DropzoneFile.php +++ b/code/DropzoneFile.php @@ -1,5 +1,7 @@ Date: Sun, 24 Jun 2018 21:16:03 +0700 Subject: [PATCH 03/13] FIX: Namespaces, expose assets --- composer.json | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1341e71..1e790ea 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,21 @@ ], "require": { - "silverstripe/framework": "3.*" + "silverstripe/framework": "4.*" }, + "autoload": { + "psr-4": { + "UncleCheese\\DropZone\\": "code/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, "extra": { - "installer-name": "dropzone" + "installer-name": "dropzone", + "expose": [ + "css", + "javascript", + "images" + ] } } From f29b75e9bb658973e72d5c0ed545a8243f361136 Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Sun, 24 Jun 2018 22:33:23 +0700 Subject: [PATCH 04/13] MINOR: Reduce length of lines --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d272ae7..c71b997 100644 --- a/README.md +++ b/README.md @@ -35,16 +35,20 @@ The Dropzone module provides `FileAttachmentField`, a robust HTML5 uploading int ## Usage -The field instantiates similarly to `UploadField`, taking the name of the file relationship and a label, as the first two arguments. Once instantiated, there are many ways to configure the UI. +The field instantiates similarly to `UploadField`, taking the name of the file relationship and a label, as the first +two arguments. Once instantiated, there are many ways to configure the UI. ```php FileAttachmentField::create('MyFile', 'Upload a file') ->setView('grid') ``` -If the form holding the upload field is bound to a record, (i.e. with `loadDataFrom()`), the upload field will automatically allow multiple files if the relation is a `has_many` or `many_many`. If the form is not bound to a record, you can use `setMultiple(true)`. +If the form holding the upload field is bound to a record, (i.e. with `loadDataFrom()`), the upload field will +automatically allow multiple files if the relation is a `has_many` or `many_many`. If the form is not bound to a record, +you can use `setMultiple(true)`. -Image-only uploads can be forced using the `imagesOnly()` method. If the form is bound to a record, and the relation points to an `Image` class, this will be automatically set. +Image-only uploads can be forced using the `imagesOnly()` method. If the form is bound to a record, and the relation +points to an `Image` class, this will be automatically set. ### More advanced options From d1cc7fd9dcf052809557e661555f87847c4e3230 Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Sun, 24 Jun 2018 22:33:41 +0700 Subject: [PATCH 05/13] FIX: Namespacing, invalid after line --- _config/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index 6327aa7..3f15f81 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,6 +1,5 @@ --- Name: dropzone -After: 'framework/*','cms/*' --- FileAttachmentField: default_config_path: javascript/default_config.json @@ -29,4 +28,4 @@ FileAttachmentField: add_remove_links: false SilverStripe\Assets\File: extensions: - - DropzoneFile + - UncleCheese\DropZone\DropzoneFile From 55a82ed0126cd73ba23411e75775ab324893b2f0 Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Sun, 24 Jun 2018 22:34:30 +0700 Subject: [PATCH 06/13] WIP: Case of many_many and has_many fix, separation of selection handler --- code/FileAttachmentField.php | 76 +------------------- code/FileAttachmentField_SelectHandler.php | 84 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 74 deletions(-) create mode 100644 code/FileAttachmentField_SelectHandler.php diff --git a/code/FileAttachmentField.php b/code/FileAttachmentField.php index fcdd8aa..28b9e37 100644 --- a/code/FileAttachmentField.php +++ b/code/FileAttachmentField.php @@ -967,7 +967,7 @@ public function IsMultiple() { } if($record = $this->getRecord()) { - return ($record->many_many($this->getName()) || $record->has_many($this->getName())); + return ($record->manyMany($this->getName()) || $record->hasMany($this->getName())); } return false; @@ -1200,7 +1200,7 @@ public function getRecord() { if (($record = $this->form->getRecord()) && ($record instanceof DataObject)) { $this->record = $record; } - elseif (($controller = $this->form->Controller()) + elseif (($controller = $this->form->getController()) && $controller->hasMethod('data') && ($record = $controller->data()) && ($record instanceof DataObject) @@ -1334,76 +1334,4 @@ public function getConfigJSON() { } } -class FileAttachmentField_SelectHandler extends UploadField_SelectHandler { - private static $allowed_actions = array ( - 'filesbyid', - ); - - /** - * @param $folderID The ID of the folder to display. - * @return FormField - */ - protected function getListField($folderID) { - // Generate the folder selection field. - $folderField = new TreeDropdownField('ParentID', _t('HtmlEditorField.FOLDER', Folder::class), Folder::class); - $folderField->setValue($folderID); - - // Generate the file list field. - $config = GridFieldConfig::create(); - $config->addComponent(new GridFieldSortableHeader()); - $config->addComponent(new GridFieldFilterHeader()); - $config->addComponent($columns = new GridFieldDataColumns()); - $columns->setDisplayFields(array( - 'StripThumbnail' => '', - 'Name' => 'Name', - 'Title' => 'Title' - )); - $config->addComponent(new GridFieldPaginator(8)); - - // If relation is to be autoset, we need to make sure we only list compatible objects. - $baseClass = $this->parent->getFileClass(); - - // Create the data source for the list of files within the current directory. - $files = DataList::create($baseClass)->filter('ParentID', $folderID); - - $fileField = new GridField('Files', false, $files, $config); - $fileField->setAttribute('data-selectable', true); - if($this->parent->IsMultiple()) { - $fileField->setAttribute('data-multiselect', true); - } - - $selectComposite = new CompositeField( - $folderField, - $fileField - ); - - return $selectComposite; - } - - - public function filesbyid(HTTPRequest $r) { - $ids = $r->getVar('ids'); - $files = File::get()->byIDs(explode(',',$ids)); - - $validIDs = array(); - $json = array (); - foreach($files as $file) { - $template = new SSViewer('FileAttachmentField_attachments'); - $html = $template->process(ArrayData::create(array( - 'File' => $file, - 'Scope' => $this->parent - ))); - - $validIDs[$file->ID] = $file->ID; - $json[] = array ( - 'id' => $file->ID, - 'html' => $html->forTemplate() - ); - } - - $this->parent->addValidFileIDs($validIDs); - return Convert::array2json($json); - } - -} diff --git a/code/FileAttachmentField_SelectHandler.php b/code/FileAttachmentField_SelectHandler.php new file mode 100644 index 0000000..2f622cb --- /dev/null +++ b/code/FileAttachmentField_SelectHandler.php @@ -0,0 +1,84 @@ +setValue($folderID); + + // Generate the file list field. + $config = GridFieldConfig::create(); + $config->addComponent(new GridFieldSortableHeader()); + $config->addComponent(new GridFieldFilterHeader()); + $config->addComponent($columns = new GridFieldDataColumns()); + $columns->setDisplayFields(array( + 'StripThumbnail' => '', + 'Name' => 'Name', + 'Title' => 'Title' + )); + $config->addComponent(new GridFieldPaginator(8)); + + // If relation is to be autoset, we need to make sure we only list compatible objects. + $baseClass = $this->parent->getFileClass(); + + // Create the data source for the list of files within the current directory. + $files = DataList::create($baseClass)->filter('ParentID', $folderID); + + $fileField = new GridField('Files', false, $files, $config); + $fileField->setAttribute('data-selectable', true); + if($this->parent->IsMultiple()) { + $fileField->setAttribute('data-multiselect', true); + } + + $selectComposite = new CompositeField( + $folderField, + $fileField + ); + + return $selectComposite; + } + + + public function filesbyid(HTTPRequest $r) { + $ids = $r->getVar('ids'); + $files = File::get()->byIDs(explode(',',$ids)); + + $validIDs = array(); + $json = array (); + foreach($files as $file) { + $template = new SSViewer('FileAttachmentField_attachments'); + $html = $template->process(ArrayData::create(array( + 'File' => $file, + 'Scope' => $this->parent + ))); + + $validIDs[$file->ID] = $file->ID; + $json[] = array ( + 'id' => $file->ID, + 'html' => $html->forTemplate() + ); + } + + $this->parent->addValidFileIDs($validIDs); + return Convert::array2json($json); + } + +} From bb9f2202664f39d4666e24e0006ab66fae00da34 Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Sun, 24 Jun 2018 22:48:46 +0700 Subject: [PATCH 07/13] FIX: Use the SS4 method of referencing assets --- _config.php | 3 --- code/FileAttachmentField.php | 12 ++++++------ 2 files changed, 6 insertions(+), 9 deletions(-) delete mode 100644 _config.php diff --git a/_config.php b/_config.php deleted file mode 100644 index 0321591..0000000 --- a/_config.php +++ /dev/null @@ -1,3 +0,0 @@ -isCMS()) { - Requirements::javascript(DROPZONE_DIR.'/javascript/file_attachment_field_backend.js'); + Requirements::javascript('unclecheese/dropzone:/javascript/file_attachment_field_backend.js'); } - Requirements::css(DROPZONE_DIR.'/css/file_attachment_field.css'); + Requirements::css('unclecheese/dropzone:/css/file_attachment_field.css'); if(!$this->getSetting('url')) { $this->settings['url'] = $this->Link('upload'); @@ -1028,7 +1028,7 @@ public function AttachedFiles() { * @return string */ public function RootThumbnailsDir() { - return $this->getSetting('thumbnailsDir') ?: DROPZONE_DIR.'/images/file-icons'; + return $this->getSetting('thumbnailsDir') ?: 'unclecheese/dropzone:/images/file-icons'; } /** @@ -1255,7 +1255,7 @@ protected function getSetting($setting) { * @return array */ protected function getDefaults() { - $file_path = BASE_PATH.'/'.DROPZONE_DIR.'/'.$this->config()->default_config_path; + $file_path = BASE_PATH.'/'.'unclecheese/dropzone:/'.$this->config()->default_config_path; if(!file_exists($file_path)) { throw new Exception("FileAttachmentField::getDefaults() - There is no config json file at $file_path"); } From eb4eac14fd3049303266ab1aee072c3e48795e8c Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Thu, 28 Jun 2018 16:00:23 +0700 Subject: [PATCH 08/13] FIXES: Upload request no longer erroring out --- _config/config.yml | 2 +- code/FileAttachmentField.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index 3f15f81..563ccc5 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,7 +1,7 @@ --- Name: dropzone --- -FileAttachmentField: +UncleCheese\Dropzone\FileAttachmentField: default_config_path: javascript/default_config.json icon_sizes: - 16 diff --git a/code/FileAttachmentField.php b/code/FileAttachmentField.php index 9b9dc20..fb4dfb5 100644 --- a/code/FileAttachmentField.php +++ b/code/FileAttachmentField.php @@ -105,7 +105,7 @@ class FileAttachmentField extends FileField { * that have been attached to the uploader client side * @var string */ - protected $previewTemplate = 'FileAttachmentField_preview'; + protected $previewTemplate = 'UncleCheese\DropZone\Includes\FileAttachmentField_preview'; /** * UploadField compatability. Used for the select handler, when KickAssets @@ -399,14 +399,17 @@ public function setMaxThumbnailFilesize($num) { * @return void */ public function addValidFileIDs(array $ids) { - $validIDs = Session::get('FileAttachmentField.validFileIDs'); + $request = Injector::inst()->get(HTTPRequest::class); + $session = $request->getSession(); + + $validIDs = $session->get('FileAttachmentField.validFileIDs'); if (!$validIDs) { $validIDs = array(); } foreach ($ids as $id) { $validIDs[$id] = $id; } - Session::set('FileAttachmentField.validFileIDs', $validIDs); + $session->set('FileAttachmentField.validFileIDs', $validIDs); } /** @@ -874,7 +877,10 @@ public function upload(HTTPRequest $request) { return $this->httpError(400, $user_message); } if($relationClass = $this->getFileClass($tmpFile['name'])) { - $fileObject = Object::create($relationClass); + // this was Object + error_log('Relation class: ' . $relationClass); + //$fileObject = DataObject::create($relationClass); + $fileObject = new $relationClass(); } try { @@ -1255,9 +1261,10 @@ protected function getSetting($setting) { * @return array */ protected function getDefaults() { - $file_path = BASE_PATH.'/'.'unclecheese/dropzone:/'.$this->config()->default_config_path; + $file_path = BASE_PATH.'/'.'dropzone/'.$this->config()->default_config_path; + error_log('FILE PATH: ' . $file_path); if(!file_exists($file_path)) { - throw new Exception("FileAttachmentField::getDefaults() - There is no config json file at $file_path"); + throw new \Exception("FileAttachmentField::getDefaults() - There is no config json file at $file_path"); } return Convert::json2array(file_get_contents($file_path)); From e03687dbd68cc515a84f70896b178f3dc897ebdb Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Thu, 28 Jun 2018 16:01:26 +0700 Subject: [PATCH 09/13] FIX: Move templates to correct path rwt namespacing --- .../{forms => UncleCheese/DropZone}/FileAttachmentField_holder.ss | 0 .../DropZone}/FileAttachmentField_holder_small.ss | 0 .../DropZone}/Includes/FileAttachmentField_attachments.ss | 0 .../DropZone}/Includes/FileAttachmentField_preview.ss | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename templates/{forms => UncleCheese/DropZone}/FileAttachmentField_holder.ss (100%) rename templates/{forms => UncleCheese/DropZone}/FileAttachmentField_holder_small.ss (100%) rename templates/{ => UncleCheese/DropZone}/Includes/FileAttachmentField_attachments.ss (100%) rename templates/{ => UncleCheese/DropZone}/Includes/FileAttachmentField_preview.ss (100%) diff --git a/templates/forms/FileAttachmentField_holder.ss b/templates/UncleCheese/DropZone/FileAttachmentField_holder.ss similarity index 100% rename from templates/forms/FileAttachmentField_holder.ss rename to templates/UncleCheese/DropZone/FileAttachmentField_holder.ss diff --git a/templates/forms/FileAttachmentField_holder_small.ss b/templates/UncleCheese/DropZone/FileAttachmentField_holder_small.ss similarity index 100% rename from templates/forms/FileAttachmentField_holder_small.ss rename to templates/UncleCheese/DropZone/FileAttachmentField_holder_small.ss diff --git a/templates/Includes/FileAttachmentField_attachments.ss b/templates/UncleCheese/DropZone/Includes/FileAttachmentField_attachments.ss similarity index 100% rename from templates/Includes/FileAttachmentField_attachments.ss rename to templates/UncleCheese/DropZone/Includes/FileAttachmentField_attachments.ss diff --git a/templates/Includes/FileAttachmentField_preview.ss b/templates/UncleCheese/DropZone/Includes/FileAttachmentField_preview.ss similarity index 100% rename from templates/Includes/FileAttachmentField_preview.ss rename to templates/UncleCheese/DropZone/Includes/FileAttachmentField_preview.ss From 53e74e21dad47168c4931ac912f4e8a467208db4 Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Thu, 28 Jun 2018 16:01:44 +0700 Subject: [PATCH 10/13] FIX: Namespacing in config --- _config/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config/config.yml b/_config/config.yml index 563ccc5..0ec2531 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,7 +1,7 @@ --- Name: dropzone --- -UncleCheese\Dropzone\FileAttachmentField: +UncleCheese\DropZone\FileAttachmentField: default_config_path: javascript/default_config.json icon_sizes: - 16 From ccc5a69537d62c1f7b46236eeee03847bb63642a Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Thu, 28 Jun 2018 16:54:08 +0700 Subject: [PATCH 11/13] FIX: Resource paths to images --- .../DropZone/Includes/FileAttachmentField_attachments.ss | 8 ++++---- .../DropZone/Includes/FileAttachmentField_preview.ss | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/UncleCheese/DropZone/Includes/FileAttachmentField_attachments.ss b/templates/UncleCheese/DropZone/Includes/FileAttachmentField_attachments.ss index da0795a..023c620 100644 --- a/templates/UncleCheese/DropZone/Includes/FileAttachmentField_attachments.ss +++ b/templates/UncleCheese/DropZone/Includes/FileAttachmentField_attachments.ss @@ -28,13 +28,13 @@ <% if $Scope.CanDetach %> <%t Dropzone.DETACHFILE 'remove' %> - + <% end_if %> <% if $Scope.CanDelete %> <%t Dropzone.MARKFORDELETION 'delete' %> - + <% end_if %> @@ -44,7 +44,7 @@
<%t Dropzone.REMOVED 'removed' %>
<%t Dropzone.CHANGEAFTERSAVE 'The change will take effect after you save.' %> - +
<% end_if %> @@ -53,7 +53,7 @@
<%t Dropzone.DELETED 'deleted' %>
<%t Dropzone.CHANGEAFTERSAVE 'The change will take effect after you save.' %> - +
<% end_if %> diff --git a/templates/UncleCheese/DropZone/Includes/FileAttachmentField_preview.ss b/templates/UncleCheese/DropZone/Includes/FileAttachmentField_preview.ss index f4d9930..3f66c31 100644 --- a/templates/UncleCheese/DropZone/Includes/FileAttachmentField_preview.ss +++ b/templates/UncleCheese/DropZone/Includes/FileAttachmentField_preview.ss @@ -1,7 +1,7 @@
  • - + @@ -20,13 +20,13 @@ - +
    <%t Dropzone.ERROR 'Oh no!' %>
    - +
  • From a7e2d81376cf9f588448c3ea0b7753d9168793aa Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Thu, 28 Jun 2018 16:56:42 +0700 Subject: [PATCH 12/13] MINOR: Remove debug and commented out code --- code/FileAttachmentField.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/code/FileAttachmentField.php b/code/FileAttachmentField.php index fb4dfb5..2841a1f 100644 --- a/code/FileAttachmentField.php +++ b/code/FileAttachmentField.php @@ -877,9 +877,6 @@ public function upload(HTTPRequest $request) { return $this->httpError(400, $user_message); } if($relationClass = $this->getFileClass($tmpFile['name'])) { - // this was Object - error_log('Relation class: ' . $relationClass); - //$fileObject = DataObject::create($relationClass); $fileObject = new $relationClass(); } @@ -1262,7 +1259,6 @@ protected function getSetting($setting) { */ protected function getDefaults() { $file_path = BASE_PATH.'/'.'dropzone/'.$this->config()->default_config_path; - error_log('FILE PATH: ' . $file_path); if(!file_exists($file_path)) { throw new \Exception("FileAttachmentField::getDefaults() - There is no config json file at $file_path"); } From f4fe21dce68e8a9c9a7a9eecd2244e390ef7d0ac Mon Sep 17 00:00:00 2001 From: Gordon Anderson Date: Thu, 28 Jun 2018 17:38:23 +0700 Subject: [PATCH 13/13] FIX: SS4 way of getting sessions, additional extension point for after a file has been uploaded --- code/FileAttachmentField.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/FileAttachmentField.php b/code/FileAttachmentField.php index 2841a1f..cb91723 100644 --- a/code/FileAttachmentField.php +++ b/code/FileAttachmentField.php @@ -419,7 +419,9 @@ public function addValidFileIDs(array $ids) { * @return array */ public function getValidFileIDs() { - $validIDs = Session::get('FileAttachmentField.validFileIDs'); + $request = Injector::inst()->get(HTTPRequest::class); + $session = $request->getSession(); + $validIDs = $session->get('FileAttachmentField.validFileIDs'); if ($validIDs && is_array($validIDs)) { return $validIDs; } @@ -916,6 +918,7 @@ public function upload(HTTPRequest $request) { } $this->addValidFileIDs($ids); + $this->extend('onAfterUploadFiles', $ids); return new HTTPResponse(implode(',', $ids), 200); }