Skip to content

Commit

Permalink
fix(SecurityID): Change FileAttachmentField to get SecurityID from th…
Browse files Browse the repository at this point in the history
…e relative <form>, 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.
  • Loading branch information
Jake Bentvelzen committed Mar 23, 2017
1 parent 2d117c6 commit 0b47afa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions code/FileAttachmentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ protected function defineFieldHolderRequirements() {
$this->imagesOnly();
}
}

if($token = $this->getForm()->getSecurityToken()) {
$this->addParam($token->getName(), $token->getSecurityID());
}
}

/**
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions javascript/file_attachment_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0b47afa

Please sign in to comment.