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

[DynmicDropdown] support class override and fix order by id #1538

Merged
merged 1 commit into from
Dec 4, 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 @@ -15,6 +15,7 @@
use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Model\DataObject;
use Pimcore\Model\Element\Service;
use Pimcore\Model\Factory;
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\Request;

Expand Down Expand Up @@ -66,7 +67,7 @@ public function optionsAction(Request $request)
usort(
$options,
function ($a, $b) use ($sort) {
$field = 'id';
$field = 'value';

if ($sort === 'byValue') {
$field = 'key';
Expand Down Expand Up @@ -94,14 +95,17 @@ function ($a, $b) use ($sort) {
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function methodsAction(Request $request)
public function methodsAction(Request $request, Factory $modelFactory)
{
$availableMethods = [];

$className = preg_replace("@[^a-zA-Z0-9_\-]@", '', $request->get('className'));

if (!empty($className)) {
$class = new \ReflectionClass('\\Pimcore\\Model\\DataObject\\' . ucfirst($className));
$fqcn = '\\Pimcore\\Model\\DataObject\\' . ucfirst($className);
$instance = $modelFactory->build($fqcn);

$class = new \ReflectionClass(get_class($instance));
$methods = $class->getMethods();

$classMethods = array_map(function (\ReflectionMethod $method) {
Expand Down Expand Up @@ -133,7 +137,7 @@ private function walkPath(Request $request, DataObject\AbstractObject $folder, $
$currentLang = $request->get('current_language');
$source = $request->get('methodName');
$className = ucfirst($request->get('className'));
$objectName = 'Pimcore\\Model\\DataObject\\' . $className;
$objectName = '\\Pimcore\\Model\\DataObject\\' . $className;

$usesI18n = false;
$children = $folder->getChildren();
Expand All @@ -159,31 +163,26 @@ private function walkPath(Request $request, DataObject\AbstractObject $folder, $
* @var DataObject\Concrete $child
*/
foreach ($children as $child) {
$class = get_class($child);
switch ($class) {
case DataObject\Folder::class:
/**
* @var DataObject\Folder $child
*/
$key = $child->getProperty('Taglabel') != '' ? $child->getProperty('Taglabel') : $child->getKey();
if ($request->get('recursive') === 'true') {
$options = $this->walkPath($request, $child, $options, $path . $this->separator . $key);
}

break;
case $objectName:
$key = $usesI18n ? $child->$source($currentLang) : $child->$source();
$options[] = [
'value' => $child->getId(),
'key' => ltrim($path . $this->separator . $key, $this->separator),
'published' => $child instanceof DataObject\Concrete ? $child->getPublished() : false,
];

if ($request->get('recursive') === 'true') {
$options = $this->walkPath($request, $child, $options, $path . $this->separator . $key);
}

break;
if ($child instanceof DataObject\Folder) {
/**
* @var DataObject\Folder $child
*/
$key = $child->getProperty('Taglabel') != '' ? $child->getProperty('Taglabel') : $child->getKey();
if ($request->get('recursive') === 'true') {
$options = $this->walkPath($request, $child, $options, $path . $this->separator . $key);
}
}
else if ($child instanceof $objectName) {
$key = $usesI18n ? $child->$source($currentLang) : $child->$source();
$options[] = [
'value' => $child->getId(),
'key' => ltrim($path . $this->separator . $key, $this->separator),
'published' => $child instanceof DataObject\Concrete ? $child->getPublished() : false,
];

if ($request->get('recursive') === 'true') {
$options = $this->walkPath($request, $child, $options, $path . $this->separator . $key);
}
}
}

Expand Down