/** * Action to set the node form of an existing node to the view * @param int $id id of the node * @param string $locale locale code to edit this node in, if not specified the locale of the * LocalizeController will be used * @return null */ public function editAction($id, $locale = null) { if ($locale !== null) { LocalizeController::setLocale($locale); $this->response->setRedirect($this->request->getBasePath() . '/edit/' . $id); return; } $currentNode = $this->node; $this->node = $this->getNode($id, true); $this->getSession()->set(self::SESSION_LAST_ACTION, 'edit'); $form = $this->getForm(); $this->node = $currentNode; $view = $this->getFormView($form); $this->response->setView($view); }
/** * Action to set the site form of an existing site to the view * @param int $id id of the site * @param string $locale locale code to edit this site in, if not specified the locale of the * LocalizeController will be used * @return null */ public function editAction($id, $locale = null) { if ($locale !== null) { LocalizeController::setLocale($locale); $this->response->setRedirect($this->request->getBasePath() . '/edit/' . $id); return; } $currentSite = $this->site; $currentNode = $this->site->node; $this->site = $this->getSite($id, 1, true); $this->node = $this->site->node; $form = $this->getForm(); $this->site = $currentSite; $this->node = $currentNode; $view = $this->getFormView($form); $this->response->setView($view); }
/** * Action to set a form with a data object to the view * @param integer $id Primary key of the data object * @param string $locale Locale code of the data * @return null */ public function editAction($id, $locale = null) { if ($this->isLocalized && $locale !== null) { LocalizeController::setLocale($locale); $this->response->setRedirect($this->request->getBasePath() . '/' . self::ACTION_EDIT . '/' . $id); return; } $data = $this->getData($id); if ($data == null) { $this->response->setRedirect($this->request->getBasePath()); return; } $this->setScaffoldReferer($this->request->getBasePath() . '/' . self::ACTION_EDIT . '/' . $id); $form = $this->getForm($data); if ($this->isReadOnly) { $form->setIsDisabled(true, SubmitCancelForm::BUTTON_SUBMIT); } $view = $this->getFormView($form, $data); $this->response->setView($view); }
/** * Look up the node which matches the query * @param string $query * @return null|zibo\core\Request Request object to dispatch a node if found, null otherwise */ private function getRequestFromQuery($query) { try { $modelManager = ModelManager::getInstance(); $nodeModel = $modelManager->getModel(NodeModel::NAME); $siteModel = $modelManager->getModel(SiteModel::NAME); } catch (OrmException $e) { return null; } $baseUrl = Url::getBaseUrl(); try { $siteUrls = $siteModel->getSiteUrls(); } catch (DatabaseException $exception) { return null; } if (array_key_exists($baseUrl, $siteUrls)) { $site = $siteUrls[$baseUrl]; } elseif (array_key_exists(0, $siteUrls)) { $site = $siteUrls[0]; } else { return null; } $routes = $this->getRoutesFromQuery($query); $node = $nodeModel->getNodeByRoutes($routes, $query, $site); if (!$node) { return $this->getRequestFromExpiredQuery($routes, $query, $site); } if ($node->dataLocale) { LocalizeController::setLocale($node->dataLocale); $i18n = I18n::getInstance(); $locale = $i18n->getLocale($node->dataLocale); $i18n->setCurrentLocale($locale); } $route = $node->getRoute(); $parameters = $this->getParametersFromQuery($query, $route); array_unshift($parameters, $node->id); return new JoppaRequest($baseUrl, $node, self::FRONTEND_CONTROLLER, IndexController::ACTION_NODE, $parameters); }