[04/09/2024] Installation du module ForcePhone pour rendre le téléphone obligatoire à la création du compte.
This commit is contained in:
87
local/modules/ForcePhone/Controller/ConfigureController.php
Normal file
87
local/modules/ForcePhone/Controller/ConfigureController.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace ForcePhone\Controller;
|
||||
|
||||
use ForcePhone\ForcePhone;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Thelia;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Tools\Version\Version;
|
||||
|
||||
class ConfigureController extends BaseAdminController
|
||||
{
|
||||
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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user