Comments (3)
OK, I couldn't find anything in the code setting the existing uploads so I've added it. If you like I can send a PR for this addition.
/**
* Set initial values to FilePondField
* See: https://pqina.nl/filepond/docs/patterns/api/filepond-object/#setting-initial-files
* @TODO: (especially in front-end) existing file-IDs may be spoofed which may result in unauthorized attachment of files
*
* @return array
*/
public function getExistingUploadsData()
{
// Both Value() & dataValue() seem to return an array eg: ['Files' => [258, 259, 257]]
$fileIDarray = $this->Value() ?: ['Files' => []];
if(!isset($fileIDarray['Files']) || !count($fileIDarray['Files'])) return [];
$existingUploads = [];
foreach($fileIDarray['Files'] as $fileID) {
if($file = File::get()->byID($fileID)){
$existingUploads[] = [
// the server file reference
'source' => (int) $fileID,
// set type to local to indicate an already uploaded file
'options' => [
'type' => 'local',
// file information
'file' => [
'name' => $file->Name,
'size' => (int) $file->getAbsoluteSize(),
'type' => $file->getMimeType(),
]
]
];
}
}
return $existingUploads;
}
public function Field($properties = array())
{
...
$config = [
...
'files' => $this->getExistingUploadsData(),
];
...
}
from silverstripe-base.
Yes sure I'd be happy to merge a PR doing that :-)
I haven't done it so far because I'm using only Filepond in scenarios where I don't need displaying existing files, but it's most certainly something I'll need someday!
from silverstripe-base.
merged into master
from silverstripe-base.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from silverstripe-base.