Admin_SnippetController::saveAction PHP Метод

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

public saveAction ( )
    public function saveAction()
    {
        try {
            if ($this->getParam("id")) {
                $snippet = Document\Snippet::getById($this->getParam("id"));
                $snippet = $this->getLatestVersion($snippet);
                $snippet->setUserModification($this->getUser()->getId());
                if ($this->getParam("task") == "unpublish") {
                    $snippet->setPublished(false);
                }
                if ($this->getParam("task") == "publish") {
                    $snippet->setPublished(true);
                }
                if ($this->getParam("task") == "publish" && $snippet->isAllowed("publish") or $this->getParam("task") == "unpublish" && $snippet->isAllowed("unpublish")) {
                    $this->setValuesToDocument($snippet);
                    try {
                        $snippet->save();
                        $this->saveToSession($snippet);
                        $this->_helper->json(["success" => true]);
                    } catch (\Exception $e) {
                        if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                            throw $e;
                        }
                        $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                    }
                } else {
                    if ($snippet->isAllowed("save")) {
                        $this->setValuesToDocument($snippet);
                        try {
                            $snippet->saveVersion();
                            $this->saveToSession($snippet);
                            $this->_helper->json(["success" => true]);
                        } catch (\Exception $e) {
                            $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                        }
                    }
                }
            }
        } catch (\Exception $e) {
            Logger::log($e);
            if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]);
            }
            throw $e;
        }
        $this->_helper->json(false);
    }