Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pimcore Bundle] Fix loading dynamic dropdown options #1340

Merged
merged 3 commits into from
Apr 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Model\DataObject;
use Pimcore\Model\Element\Service;
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -31,7 +32,10 @@ final class DynamicDropdownController extends AdminController
public function optionsAction(Request $request)
{
$folderName = $request->get('folderName');
$parentFolderPath = preg_replace('@[^a-zA-Z0-9/\-_\s]@', '', $folderName);
$parts = array_map(static function ($part) {
return Service::getValidKey($part, 'object');
}, preg_split('/\//', $folderName, null, PREG_SPLIT_NO_EMPTY));
$parentFolderPath = sprintf('/%s', implode('/', $parts));
$sort = $request->get('sortBy');
$options = [];

Expand All @@ -45,20 +49,7 @@ public function optionsAction(Request $request)
$parentFolderPath = str_replace('//', '/', $parentFolderPath);

$folder = DataObject\Folder::getByPath($parentFolderPath);

if ($folder) {
$options = $this->walkPath($request, $folder);
} else {
$message = sprintf('The folder submitted could not be found: "%s"', $folderName);

return $this->json(
[
'success' => false,
'message' => $message,
'options' => $options,
]
);
}
$options = $folder instanceof DataObject\AbstractObject ? $this->walkPath($request, $folder) : [];
} else {
$message = sprintf('The folder submitted for parentId is not valid: "%s"', $folderName);

Expand Down