ENH Add support for uploading multiple files to the file upload field#1367
ENH Add support for uploading multiple files to the file upload field#1367rasstislav wants to merge 1 commit into
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. |
GuySartorelli
left a comment
There was a problem hiding this comment.
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($data[$field->Name])) { | ||
| if (in_array(EditableFileField::class, $field->getClassAncestry() ?? [])) { | ||
| 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.
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.
Please move this callback to be a private method in this class instead of an anonymous function.
| private static $db = [ | ||
| 'MaxFileSizeMB' => 'Float', | ||
| 'FolderConfirmed' => 'Boolean', | ||
| 'Multiple' => 'Boolean', |
There was a problem hiding this comment.
| 'Multiple' => 'Boolean', | |
| 'IsMultiple' => 'Boolean', |
| 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.
| $field = FileField::create(($originalName = $this->Name) . ($this->Multiple ? '[]' : ''), $this->Title ?: false) | |
| $field = FileField::create($this->Name . ($this->Multiple ? '[]' : ''), $this->Title ?: false) |
|
|
||
| $this->doUpdateFormField($field); | ||
|
|
||
| $field->setAttribute('htmlID', $originalName); |
There was a problem hiding this comment.
| $field->setAttribute('htmlID', $originalName); | |
| $field->setAttribute('htmlID', $this->Name); |
|
|
||
| $this->doUpdateFormField($field); | ||
|
|
||
| $field->setAttribute('htmlID', $originalName); |
| private static $has_one = [ | ||
| 'UploadedFile' => File::class | ||
| ]; | ||
|
|
||
| private static $many_many = [ | ||
| 'UploadedFiles' => File::class | ||
| ]; |
There was a problem hiding this comment.
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.
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.
| * @return array<File>|null | ||
| */ | ||
| public function getUploadedFileFromDraft() | ||
| public function getUploadedFilesFromDraft() |
There was a problem hiding this comment.
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.
| <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.
Please do this for all other cases where a string is being passed to a function from a template.
Issues
Pull request checklist