/** * Main action for editing hub modules */ public function editHubAction() { global $wgCityId; if (!$this->checkAccess()) { return false; } $this->retriveDataFromUrl(); $this->wg->Out->addJsConfigVars(['wgEditHubModuleIdSelected' => $this->selectedModuleId, 'wgEditHubModuleIdPopularVideos' => WikiaHubsModulePopularvideosService::MODULE_ID, 'wgEditHubModuleIdFeaturedVideo' => WikiaHubsModuleFeaturedvideoService::MODULE_ID]); $this->checkDate($this->date); $this->flashMessage = FlashMessages::pop(); $modulesData = $this->editHubModel->getModulesData($wgCityId, $this->date, $this->selectedModuleId); $this->prepareLayoutData($this->selectedModuleId, $modulesData); $this->response->addAsset('resources/jquery/jquery.validate.js'); $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/EditHub.js'); $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/EditHubNavigation.js'); $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/jquery.MetaData.js'); $selectedModuleValues = $modulesData['moduleList'][$this->selectedModuleId]['data']; $module = WikiaHubsModuleService::getModuleByName($this->editHubModel->getNotTranslatedModuleName($this->selectedModuleId), $wgCityId); $form = new FormBuilderService(EditHubModel::FORM_FIELD_PREFIX); $form->setFields($module->getFormFields()); if ($this->request->wasPosted()) { $selectedModuleValues = $this->request->getParams(); $selectedModuleValues = $module->filterData($selectedModuleValues); $isValid = $form->validate($selectedModuleValues); if ($isValid) { $this->editHubModel->saveModule(['cityId' => $wgCityId, 'langCode' => $this->wg->ContLang->getCode(), 'verticalId' => WikiFactoryHub::getInstance()->getCategoryId($wgCityId)], $this->date, $this->selectedModuleId, $selectedModuleValues, $this->wg->user->getId()); $this->purgeCache($module); FlashMessages::put(wfMessage('edit-hub-module-save-ok', $modulesData['activeModuleName'])->escaped()); $nextUrl = $this->getNextModuleUrl(); $this->response->redirect($nextUrl); } else { $this->errorMessage = wfMessage('edit-hub-module-save-error')->escaped(); } } $form->setFieldsValues($selectedModuleValues); $this->moduleName = $modulesData['activeModuleName']; $this->moduleContent = $module->renderEditor(['form' => $form]); $this->overrideTemplate('editHub'); }