public function onModuleConfigure(HookRenderEvent $event) { $vars = []; if (null !== ($params = ModuleConfigQuery::create()->findByModuleId(ForcePhone::getModuleId()))) { /** @var ModuleConfig $param */ foreach ($params as $param) { $vars[$param->getName()] = $param->getValue(); } } $event->add($this->render('force-phone/module-configuration.html', $vars)); }
public function forcePhoneInput(TheliaFormEvent $event) { if ($this->request->fromApi() === false) { if (ForcePhone::getConfigValue('force_one', false)) { $constraints = [new AtLeastOnePhone()]; } else { $constraints = []; } $forcePhone = ForcePhone::getConfigValue('force_phone', false); if (!empty($constraints) || $forcePhone) { $event->getForm()->getFormBuilder()->remove('phone')->add("phone", "text", ["constraints" => $forcePhone ? [new NotBlank()] : $constraints, "label" => Translator::getInstance()->trans("Phone"), "label_attr" => ["for" => "phone"], "required" => $forcePhone]); } $forceCellPhone = ForcePhone::getConfigValue('force_cellphone', false); if (!empty($constraints) || $forceCellPhone) { $event->getForm()->getFormBuilder()->remove('cellphone')->add("cellphone", "text", ["constraints" => $forceCellPhone ? [new NotBlank()] : $constraints, "label" => Translator::getInstance()->trans("Cellphone"), "label_attr" => ["for" => "cellphone"], "required" => $forceCellPhone]); } } }
public function configure() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'forcephone', AccessManager::UPDATE))) { return $response; } $configurationForm = $this->createForm('forcephone_configuration'); $message = null; try { $form = $this->validateForm($configurationForm); // Get the form field values $data = $form->getData(); foreach ($data as $name => $value) { if (is_array($value)) { $value = implode(';', $value); } ForcePhone::setConfigValue($name, $value); } // Log configuration modification $this->adminLogAppend("forcephone.configuration.message", AccessManager::UPDATE, "ForcePhone configuration updated"); // Redirect to the success URL, if ($this->getRequest()->get('save_mode') == 'stay') { // If we have to stay on the same page, redisplay the configuration page/ $url = '/admin/module/ForcePhone'; } else { // If we have to close the page, go back to the module back-office page. $url = '/admin/modules'; } return $this->generateRedirect(URL::getInstance()->absoluteUrl($url)); } catch (FormValidationException $ex) { $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { $message = $ex->getMessage(); } $this->setupFormErrorContext($this->getTranslator()->trans("ForcePhone configuration", [], ForcePhone::DOMAIN_NAME), $message, $configurationForm, $ex); // Before 2.2, the errored form is not stored in session if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { return $this->render('module-configure', ['module_code' => 'ForcePhone']); } else { return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/ForcePhone')); } }