Externalisation de la clé API Google dans la config du module PlanificationLivraison
This commit is contained in:
66
local/modules/PlanificationLivraison/Controller/Configuration.php
Executable file
66
local/modules/PlanificationLivraison/Controller/Configuration.php
Executable file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace PlanificationLivraison\Controller;
|
||||
|
||||
use PlanificationLivraison\PlanificationLivraison;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class Configuration
|
||||
* @package PlanificationLivraison\Controller
|
||||
*/
|
||||
class Configuration extends BaseAdminController
|
||||
{
|
||||
public function editConfig()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(
|
||||
AdminResources::MODULE,
|
||||
[PlanificationLivraison::DOMAIN_NAME],
|
||||
AccessManager::UPDATE
|
||||
)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = $this->createForm('planiflivraison.configuration');
|
||||
$error_message = null;
|
||||
|
||||
try {
|
||||
$validateForm = $this->validateForm($form);
|
||||
$data = $validateForm->getData();
|
||||
|
||||
PlanificationLivraison::setConfigValue(
|
||||
PlanificationLivraison::CONFIG_VALUE_NAME,
|
||||
$data["google_api_key"]
|
||||
);
|
||||
|
||||
return $this->redirectToConfigurationPage();
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$error_message = $this->createStandardFormValidationErrorMessage($e);
|
||||
}
|
||||
|
||||
if (null !== $error_message) {
|
||||
$this->setupFormErrorContext(
|
||||
'configuration',
|
||||
$error_message,
|
||||
$form
|
||||
);
|
||||
$response = $this->render("module-configure", ['module_code' => 'PlanificationLivraison']);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the configuration page
|
||||
*/
|
||||
protected function redirectToConfigurationPage()
|
||||
{
|
||||
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/PlanificationLivraison'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user