public function saveAction()
{
$class = Object\ClassDefinition::getById(intval($this->getParam("id")));
$configuration = \Zend_Json::decode($this->getParam("configuration"));
$values = \Zend_Json::decode($this->getParam("values"));
// check if the class was changed during editing in the frontend
if ($class->getModificationDate() != $values["modificationDate"]) {
throw new \Exception("The class was modified during editing, please reload the class and make your changes again");
}
if ($values["name"] != $class->getName()) {
$values["name"] = $this->correctClassname($values["name"]);
$class->rename($values["name"]);
}
unset($values["creationDate"]);
unset($values["userOwner"]);
unset($values["layoutDefinitions"]);
unset($values["fieldDefinitions"]);
$configuration["datatype"] = "layout";
$configuration["fieldtype"] = "panel";
$configuration["name"] = "pimcore_root";
$class->setValues($values);
try {
$layout = Object\ClassDefinition\Service::generateLayoutTreeFromArray($configuration, true);
$class->setLayoutDefinitions($layout);
$class->setUserModification($this->user->getId());
$class->setModificationDate(time());
$propertyVisibility = [];
foreach ($values as $key => $value) {
if (preg_match("/propertyVisibility/i", $key)) {
if (preg_match("/\\.grid\\./i", $key)) {
$propertyVisibility["grid"][preg_replace("/propertyVisibility\\.grid\\./i", "", $key)] = (bool) $value;
} elseif (preg_match("/\\.search\\./i", $key)) {
$propertyVisibility["search"][preg_replace("/propertyVisibility\\.search\\./i", "", $key)] = (bool) $value;
}
}
}
if (!empty($propertyVisibility)) {
$class->setPropertyVisibility($propertyVisibility);
}
$class->save();
// set the fielddefinitions to null because we don't need them in the response
$class->setFieldDefinitions(null);
$this->_helper->json(["success" => true, "class" => $class]);
} catch (\Exception $e) {
Logger::error($e->getMessage());
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
}