mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 11:26:04 +01:00
Use Media class to retrieve files in AdminController#taskGetFilesInFolder (#842)
Using the same class that's used to list media when rendering pages ensures a consistent experience. The goal here was to avoid listing image alternatives, but retain all the files available through $page->media()->all()
This commit is contained in:
committed by
Flavio Copes
parent
f82661abea
commit
a42fd33c4f
@@ -349,7 +349,7 @@ class AdminController
|
||||
protected function taskGetFilesInFolder()
|
||||
{
|
||||
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->view == 'pages' ? $this->admin->page(true) : $this->prepareData([]);
|
||||
@@ -374,7 +374,12 @@ class AdminController
|
||||
$folder = Folder::getRelativePath(rtrim($folder, '/'));
|
||||
$folder = $this->admin->getPagePathFromToken($folder);
|
||||
|
||||
$available_files = Folder::all($folder, ['recursive' => false]);
|
||||
$media = new Media($folder);
|
||||
$available_files = [];
|
||||
|
||||
foreach ($media->all() as $name => $medium) {
|
||||
$available_files[] = $name;
|
||||
}
|
||||
|
||||
// Peak in the flashObject for optimistic filepicker updates
|
||||
$pending_files = [];
|
||||
@@ -407,8 +412,8 @@ class AdminController
|
||||
|
||||
$this->admin->json_response = [
|
||||
'status' => 'success',
|
||||
'files' => $available_files,
|
||||
'pending' => $pending_files,
|
||||
'files' => array_values($available_files),
|
||||
'pending' => array_values($pending_files),
|
||||
'folder' => $folder
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user