Pimcore\Model\Object\Classificationstore\KeyConfig::save PHP Метод

save() публичный Метод

Saves the key config
public save ( )
    public function save()
    {
        DefinitionCache::clear($this);
        $isUpdate = false;
        $def = \Zend_Json::decode($this->definition);
        if ($def && isset($def["title"])) {
            $this->title = $def["title"];
        } else {
            $this->title = null;
        }
        if ($this->getId()) {
            unset(self::$cache[$this->getId()]);
            $isUpdate = true;
            \Pimcore::getEventManager()->trigger("object.classificationstore.keyConfig.preUpdate", $this);
        } else {
            \Pimcore::getEventManager()->trigger("object.classificationstore.keyConfig.preAdd", $this);
        }
        $model = parent::save();
        if ($isUpdate) {
            \Pimcore::getEventManager()->trigger("object.classificationstore.keyConfig.postUpdate", $this);
        } else {
            \Pimcore::getEventManager()->trigger("object.classificationstore.keyConfig.postAdd", $this);
        }
        return $model;
    }

Usage Example

 public function addPropertyAction()
 {
     $name = $this->getParam("name");
     $alreadyExist = false;
     if (!$alreadyExist) {
         $definition = array("fieldtype" => "input", "name" => $name, "title" => $name, "datatype" => "data");
         $config = new Classificationstore\KeyConfig();
         $config->setName($name);
         $config->setTitle($name);
         $config->setType("input");
         $config->setEnabled(1);
         $config->setDefinition(json_encode($definition));
         $config->save();
     }
     $this->_helper->json(array("success" => !$alreadyExist, "id" => $config->getName()));
 }