From 0b47afa15e5bfb8022fa7f08ed453f8b52852469 Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Thu, 23 Mar 2017 12:19:58 +1100 Subject: [PATCH] fix(SecurityID): Change FileAttachmentField to get SecurityID from the relative
, this was to fix DynamicCache incompatibilities as it uses regex on cached HTML pages to replace the SecurityID appropriately. - $data['params'] is set to null to avoid it being a regular array when being converted to JavaScript when it's empty. --- code/FileAttachmentField.php | 6 +----- javascript/file_attachment_field.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/code/FileAttachmentField.php b/code/FileAttachmentField.php index c946557..83b4a31 100644 --- a/code/FileAttachmentField.php +++ b/code/FileAttachmentField.php @@ -199,10 +199,6 @@ protected function defineFieldHolderRequirements() { $this->imagesOnly(); } } - - if($token = $this->getForm()->getSecurityToken()) { - $this->addParam($token->getName(), $token->getSecurityID()); - } } /** @@ -1180,7 +1176,7 @@ public function getConfigJSON() { } } - $data['params'] = $this->params; + $data['params'] = ($this->params) ? $this->params : null; $data['thumbnailsDir'] = $this->ThumbnailsDir(); $data['thumbnailWidth'] = $this->getSelectedThumbnailWidth(); $data['thumbnailHeight'] = $this->getSelectedThumbnailHeight(); diff --git a/javascript/file_attachment_field.js b/javascript/file_attachment_field.js index e63bcb1..52d52db 100644 --- a/javascript/file_attachment_field.js +++ b/javascript/file_attachment_field.js @@ -13,6 +13,20 @@ var UploadInterface = function (node, backend) { this.settings = JSON.parse(node.getAttribute('data-config')); this.node = node; this.droppedFiles = []; + if (!this.settings.params) { + this.settings.params = {}; + } + + if (!this.settings.params.SecurityID) { + var formNode = this.node; + do { + formNode = formNode.parentNode; + } while (formNode && formNode.tagName !== 'FORM' && formNode.nodeType !== 11); + var securityIDNode = formNode.querySelector("input[name=\"SecurityID\"]"); + if (securityIDNode) { + this.settings.params.SecurityID = securityIDNode.value; + } + } if(template) { this.settings.previewTemplate = template.innerHTML;