Skip to content

Commit

Permalink
Merge pull request #1038 from dpfaffenbauer/dynamic-dropdown
Browse files Browse the repository at this point in the history
[PimcoreBundle] use reflection to get class methods
  • Loading branch information
dpfaffenbauer authored Jun 24, 2019
2 parents 386249a + 510c71d commit cc3c1b3
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,26 @@ function ($a, $b) use ($sort) {
*/
public function methodsAction(Request $request)
{
$methods = [];
$availableMethods = [];

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

if (!empty($className)) {
$classMethods = $this->getThisClassMethods('\\Pimcore\\Model\\DataObject\\' . ucfirst($className));
$class = new \ReflectionClass('\\Pimcore\\Model\\DataObject\\' . ucfirst($className));
$methods = $class->getMethods();

if (!is_null($classMethods)) {
foreach ($classMethods as $methodName) {
if (substr($methodName, 0, 3) == 'get') {
$methods[] = ['value' => $methodName, 'key' => $methodName];
}
$classMethods = array_map(function(\ReflectionMethod $method) {
return $method->getName();
}, $methods);

foreach ($classMethods as $methodName) {
if (substr($methodName, 0, 3) === 'get') {
$availableMethods[] = ['value' => $methodName, 'key' => $methodName];
}
}
}

return $this->json($methods);
return $this->json($availableMethods);
}

/**
Expand Down

0 comments on commit cc3c1b3

Please sign in to comment.