Skip to content

Commit

Permalink
Added custom object support for filepicker field
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 16, 2018
1 parent 44715ee commit ee8e488
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.8.2
## mm/dd/2018

1. [](#bugfix)
* Added custom object support for filepicker field

# v1.8.1
## 05/15/2018

Expand Down
40 changes: 28 additions & 12 deletions classes/adminbasecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
namespace Grav\Plugin\Admin;

use Grav\Common\Config\Config;
use Grav\Common\Data\Data;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Grav;
use Grav\Common\Media\Interfaces\MediaInterface;
use Grav\Common\Page\Media;
use Grav\Common\Utils;
use Grav\Common\Plugin;
Expand Down Expand Up @@ -743,8 +745,17 @@ protected function taskGetFilesInFolder()
return false;
}

$data = $this->view === 'pages' ? $this->admin->page(true) : $this->prepareData([]);
$settings = $data->blueprints()->schema()->getProperty($this->post['name']);
$data = $this->view === 'pages' ? $this->admin->page(true) : $this->prepareData([]);

if (null === $data) {
return false;
}

if ($data instanceof Data) {
$settings = $data->blueprints()->schema()->getProperty($this->post['name']);
} elseif (method_exists($data, 'getBlueprint')) {
$settings = $data->getBlueprint()->schema()->getProperty($this->post['name']);
}

if (isset($settings['folder'])) {
$folder = $settings['folder'];
Expand All @@ -754,19 +765,24 @@ protected function taskGetFilesInFolder()

// Do not use self@ outside of pages
if ($this->view !== 'pages' && in_array($folder, ['@self', 'self@', '@self@'])) {
$this->admin->json_response = [
'status' => 'error',
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null), $folder)
];
if (!$data instanceof MediaInterface) {
$this->admin->json_response = [
'status' => 'error',
'message' => sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_PREVENT_SELF', null), $folder)
];

return false;
}
return false;
}

// Set destination
$folder = Folder::getRelativePath(rtrim($folder, '/'));
$folder = $this->admin->getPagePathFromToken($folder);
$media = $data->getMedia();
} else {
// Set destination
$folder = Folder::getRelativePath(rtrim($folder, '/'));
$folder = $this->admin->getPagePathFromToken($folder);

$media = new Media($folder);
}

$media = new Media($folder);
$available_files = [];
$metadata = [];
$thumbs = [];
Expand Down

0 comments on commit ee8e488

Please sign in to comment.