From acca6dbf4f93a4a54ffd6b6ce796957728e1384d Mon Sep 17 00:00:00 2001 From: Lorenzo Nicoletti Date: Tue, 19 May 2015 14:11:53 +0200 Subject: [PATCH] fix: options generation in case of overriding object class --- controllers/DynamicdropdownController.php | 37 ++++++++++------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/controllers/DynamicdropdownController.php b/controllers/DynamicdropdownController.php index f49af72..34a2177 100644 --- a/controllers/DynamicdropdownController.php +++ b/controllers/DynamicdropdownController.php @@ -1,6 +1,6 @@ "@[^a-zA-Z0-9/\-_]@", "replace" => "")); $parentFolderPath = $filter->filter($this->_getParam("source_parent")); - - + + if ($parentFolderPath) { // remove trailing slash if($parentFolderPath != "/") { @@ -37,7 +37,7 @@ public function optionsAction() { // correct wrong path (root-node problem) $parentFolderPath = str_replace("//","/",$parentFolderPath); - + $folder = Object_Folder::getByPath($parentFolderPath); if ($folder) { $options = $this->walk_path($folder); @@ -64,7 +64,7 @@ private function walk_path($folder, $options = null, $path = "") { if ($folder) { $source = $this->_getParam("source_methodname"); - + if (Pimcore_Version::getRevision() > 3303) { $object_name = "Pimcore\\Model\\Object\\" . ucfirst($this->_getParam("source_classname")); } else { @@ -81,39 +81,34 @@ private function walk_path($folder, $options = null, $path = "") { $current_lang = $languages[0]; // TODO: Is this sensible? } foreach ($children as $child) { - $class = get_class($child); - switch ($class) { - case "Object_Folder": - /** - * @var Object_Folder $child - */ - + if ($child instanceof \Pimcore\Model\Object\Folder) { + /* Case: Folder*/ $key = $child->getProperty("Taglabel") != "" ? $child->getProperty("Taglabel") : $child->getKey(); if ($this->_getParam("source_recursive") == "true") $options = $this->walk_path($child, $options, $path.$this->separator.$key); - break; - case $object_name: + + } elseif (is_a($child, $object_name)) { + /* Case: Object*/ $key = $usesI18n ? $child->$source($current_lang) : $child->$source(); $options[] = array( "value" => $child->getId(), "key" => ltrim($path.$this->separator.$key, $this->separator) ); if ($this->_getParam("source_recursive") == "true") - $options = $this->walk_path($child, $options, $path.$this->separator.$key); - break; + $options = $this->walk_path($child, $options, $path . $this->separator . $key); } } } return $options; } - + /** * Produces the json for the "available methods" dropdown in the backend. * used by pimcore.object.classes.data.dynamicDropdown */ public function methodsAction() { $methods = array(); - + $filter = new Zend_Filter_PregReplace(array("match" => "@[^a-zA-Z0-9_\-]@", "replace" => "")); $class_name = $filter->filter($this->_getParam("classname")); if (!empty($class_name)) { @@ -134,7 +129,7 @@ public function methodsAction() { */ private function isUsingI18n(Pimcore\Model\Object\Concrete $object, $method) { $modelId = $object->getClassId(); - + // Stolen from Object_Class_Resource - it's protected there. $file = PIMCORE_CLASS_DIRECTORY."/definition_".$modelId.".psf"; if(!is_file($file)) { @@ -143,9 +138,9 @@ private function isUsingI18n(Pimcore\Model\Object\Concrete $object, $method) { $tree = unserialize(file_get_contents($file)); $definition = $this->parse_tree($tree, array()); return $definition[$method]; - + } - + private function parse_tree($tree, $definition) { $class = get_class($tree); if (is_a($tree, "Object_Class_Layout") || is_a($tree, "Object_Class_Data_Localizedfields")) { // Did I forget something?