Skip to content
Snippets Groups Projects
Commit 3e33ff67 authored by Peter Rotich's avatar Peter Rotich
Browse files

files: FileUploadWidget render

Use file id instead of attachment id to unset new
Get new files objects as array
parent 28e6c2e2
Branches
Tags
No related merge requests found
...@@ -3668,17 +3668,19 @@ class FileUploadWidget extends Widget { ...@@ -3668,17 +3668,19 @@ class FileUploadWidget extends Widget {
$maxfilesize = ($config['size'] ?: 1048576) / 1048576; $maxfilesize = ($config['size'] ?: 1048576) / 1048576;
$files = $F = array(); $files = $F = array();
$new = array_fill_keys($this->field->getClean(), 1); $new = array_fill_keys($this->field->getClean(), 1);
foreach ($attachments as $f) { foreach ($attachments as $a) {
$F[] = $f->file; $F[] = $a->file;
unset($new[$f->id]); unset($new[$a->file_id]);
} }
// Add in newly added files not yet saved (if redisplaying after an // Add in newly added files not yet saved (if redisplaying after an
// error) // error)
if ($new) { if ($new) {
$F = array_merge($F, AttachmentFile::objects() $F = array_merge($F, AttachmentFile::objects()
->filter(array('id__in' => array_keys($new))) ->filter(array('id__in' => array_keys($new)))
->all()); ->all()
);
} }
foreach ($F as $file) { foreach ($F as $file) {
$files[] = array( $files[] = array(
'id' => $file->getId(), 'id' => $file->getId(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment