-
Notifications
You must be signed in to change notification settings - Fork 225
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
ENH Add support for uploading multiple files to the file upload field #1367
base: 6
Are you sure you want to change the base?
Conversation
faad61f
to
adee684
Compare
adee684
to
5454e25
Compare
In the future please do not remove sections from the pull request template - having a quick description and manual testing steps in the PR description goes a long way to making reviews easier and faster, and therefore more likely to happen. |
You haven't ticked the checkbox "This change is covered with tests (or tests aren't necessary for this change)" - this implies you think tests are required and haven't added them. If tests are needed, please add them. |
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.
Haven't done a thorough review, but these things stood out to me.
Please note that we'll be releasing CMS 5.4.0-beta1 soon, hopefully some time this week, and that is also the change freeze for any changes for CMS 5.
I don't think it's likely this will be approved for merging before then, so it probably makes sense to retarget this to the 7
branch with the intention of it being included in the next major release.
if (!empty($_FILES[$field->Name]['name'])) { | ||
if (($names = $_FILES[$field->Name]['name'] ?? '') && (!is_array($names) || array_filter($names))) { |
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.
Please move the variable assignment to be outside the if()
$validationResult = $e->getResult(); | ||
foreach ($validationResult->getMessages() as $message) { | ||
$form->sessionMessage($message['message'], ValidationResult::TYPE_ERROR); | ||
$processFile = function ($fileData) use ($field, $form, &$attachments) { |
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.
Please move this callback to be a private method in this class instead of an anonymous function.
@@ -40,6 +42,7 @@ class EditableFileField extends EditableFormField | |||
private static $db = [ | |||
'MaxFileSizeMB' => 'Float', | |||
'FolderConfirmed' => 'Boolean', | |||
'Multiple' => 'Boolean', |
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.
'Multiple' => 'Boolean', | |
'IsMultiple' => 'Boolean', |
@@ -209,7 +218,7 @@ public function createProtectedFolder(): void | |||
|
|||
public function getFormField() | |||
{ | |||
$field = FileField::create($this->Name, $this->Title ?: false) | |||
$field = FileField::create(($originalName = $this->Name) . ($this->Multiple ? '[]' : ''), $this->Title ?: false) |
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.
$field = FileField::create(($originalName = $this->Name) . ($this->Multiple ? '[]' : ''), $this->Title ?: false) | |
$field = FileField::create($this->Name . ($this->Multiple ? '[]' : ''), $this->Title ?: false) |
@@ -240,6 +253,8 @@ public function getFormField() | |||
|
|||
$this->doUpdateFormField($field); | |||
|
|||
$field->setAttribute('htmlID', $originalName); |
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.
$field->setAttribute('htmlID', $originalName); | |
$field->setAttribute('htmlID', $this->Name); |
@@ -240,6 +253,8 @@ public function getFormField() | |||
|
|||
$this->doUpdateFormField($field); | |||
|
|||
$field->setAttribute('htmlID', $originalName); |
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.
Where is this used?
private static $has_one = [ | ||
'UploadedFile' => File::class | ||
]; | ||
|
||
private static $many_many = [ | ||
'UploadedFiles' => File::class | ||
]; |
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.
Feels bad having both of these, but I guess we have to do this until the next major release.
* @return string | ||
* @return array|null | ||
*/ | ||
public function getLink($grant = true) | ||
public function getLinks($grant = true) |
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.
We can't just rename methods outside of a major release.
Either target this to the 7
branch or implement a new method and deprecate the old one.
*/ | ||
public function getUploadedFileFromDraft() | ||
public function getUploadedFilesFromDraft() |
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.
We can't just rename methods outside of a major release.
Either target this to the 7
branch or implement a new method and deprecate the old one.
@@ -1,2 +1,2 @@ | |||
<input type="hidden" name="MAX_FILE_SIZE" value="$MaxFileSize" /> | |||
<input $AttributesHTML<% if $RightTitle %> aria-describedby="{$Name}_right_title"<% end_if %>/> | |||
<input $getAttributesHTML(htmlID)<% if $RightTitle %> aria-describedby="{$getAttribute(htmlID)}_right_title"<% end_if %>/> |
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.
<input $getAttributesHTML(htmlID)<% if $RightTitle %> aria-describedby="{$getAttribute(htmlID)}_right_title"<% end_if %>/> | |
<input $getAttributesHTML("htmlID")<% if $RightTitle %> aria-describedby="{$getAttribute("htmlID")}_right_title"<% end_if %>/> |
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.
Please do this for all other cases where a string is being passed to a function from a template.
Issues
Pull request checklist