public function saveAction() { if (null !== ($response = $this->checkAuth([AdminResources::MODULE], ["storeseo"], AccessManager::UPDATE))) { return $response; } $baseForm = $this->createForm("storeseo_form_config"); $errorMessage = null; // Get current edition language locale $locale = $this->getCurrentEditionLocale(); try { $form = $this->validateForm($baseForm); $data = $form->getData(); // Save data StoreSeo::setConfigValue('title', $data["title"], $locale); StoreSeo::setConfigValue('description', $data["description"], $locale); StoreSeo::setConfigValue('keywords', $data["keywords"], $locale); } catch (FormValidationException $ex) { // Invalid data entered $errorMessage = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], StoreSeo::DOMAIN_NAME, $locale); } if (null !== $errorMessage) { // Mark the form as with error $baseForm->setErrorMessage($errorMessage); // Send the form and the error to the parser $this->getParserContext()->addForm($baseForm)->setGeneralError($errorMessage); } else { $this->getParserContext()->set("success", true); } return $this->defaultAction(); }
/** * Assign meta title, description and keyword for the template * * @param array $params * @param \Smarty $smarty */ public function changeSeoMeta($params, &$smarty) { // Get language and moduleConfig $locale = $params['locale']; // Get store title $smarty->assign("store_name", StoreSeo::getConfigValue('title', null, $locale)); // Get store description $smarty->assign("store_description", StoreSeo::getConfigValue('description', null, $locale)); // Get store keywords $smarty->assign("default_keywords", StoreSeo::getConfigValue('keywords', null, $locale)); }