From 0637bffcf56129e493e07bea557b99e953c96c0b Mon Sep 17 00:00:00 2001 From: Fredrik Ekelund Date: Wed, 26 Oct 2016 23:18:48 +0200 Subject: [PATCH] Use Media class to retrieve files in AdminController#taskGetFilesInFolder 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() --- classes/controller.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/classes/controller.php b/classes/controller.php index cbe024284..764c0aa0a 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -349,7 +349,7 @@ protected function taskKeepAlive() 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 @@ protected function taskGetFilesInFolder() $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 @@ protected function taskGetFilesInFolder() $this->admin->json_response = [ 'status' => 'success', - 'files' => $available_files, - 'pending' => $pending_files, + 'files' => array_values($available_files), + 'pending' => array_values($pending_files), 'folder' => $folder ];