public static function generateLayoutTreeFromArray($array, $throwException = false)
{
if (is_array($array) && count($array) > 0) {
$class = "\\Pimcore\\Model\\Object\\ClassDefinition\\" . ucfirst($array["datatype"]) . "\\" . ucfirst($array["fieldtype"]);
if (!\Pimcore\Tool::classExists($class)) {
$class = "\\Object_Class_" . ucfirst($array["datatype"]) . "_" . ucfirst($array["fieldtype"]);
if (!\Pimcore\Tool::classExists($class)) {
$class = null;
}
}
if ($class) {
$item = new $class();
if (method_exists($item, "addChild")) {
// allows childs
$item->setValues($array, ["childs"]);
if (is_array($array) && is_array($array["childs"]) && $array["childs"]["datatype"]) {
$childO = self::generateLayoutTreeFromArray($array["childs"], $throwException);
$item->addChild($childO);
} elseif (is_array($array["childs"]) && count($array["childs"]) > 0) {
foreach ($array["childs"] as $child) {
$childO = self::generateLayoutTreeFromArray($child, $throwException);
if ($childO !== false) {
$item->addChild($childO);
} else {
if ($throwException) {
throw new \Exception("Could not add child " . var_export($child, true));
}
return false;
}
}
}
} else {
$item->setValues($array);
}
return $item;
}
}
if ($throwException) {
throw new \Exception("Could not add child " . var_export($array, true));
}
return false;
}