-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
344 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
local/modules/HookAdminHome/Controller/ConfigurationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
<?php | |||
|
|||
|
|||
namespace HookAdminHome\Controller; | |||
|
|||
use HookAdminHome\HookAdminHome; | |||
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 ConfigurationController extends BaseAdminController | |||
{ | |||
|
|||
public function editConfiguration() | |||
{ | |||
if (null !== $response = $this->checkAuth( | |||
AdminResources::MODULE, | |||
[HookAdminHome::DOMAIN_NAME], | |||
AccessManager::UPDATE | |||
)) { | |||
return $response; | |||
} | |||
|
|||
$form = $this->createForm('hookadminhome.config.form'); | |||
$error_message = null; | |||
|
|||
try { | |||
$validateForm = $this->validateForm($form); | |||
$data = $validateForm->getData(); | |||
|
|||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_NEWS, 0); | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_SALES, 0); | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_INFO, 0); | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_STATS, 0); | |||
|
|||
if($data['enabled-news']){ | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_NEWS, 1); | |||
} | |||
|
|||
if($data['enabled-sales']){ | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_SALES, 1); | |||
} | |||
|
|||
if($data['enabled-info']){ | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_INFO, 1); | |||
} | |||
|
|||
if($data['enabled-stats']){ | |||
HookAdminHome::setConfigValue(HookAdminHome::ACTIVATE_STATS, 1); | |||
} | |||
|
|||
return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/HookAdminHome')); | |||
|
|||
} 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' => 'HookAdminHome']); | |||
} | |||
return $response; | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,93 @@ | |||
<?php | |||
|
|||
namespace HookAdminHome\Form; | |||
|
|||
use HookAdminHome\HookAdminHome; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
use Thelia\Core\Translation\Translator; | |||
use Thelia\Form\BaseForm; | |||
|
|||
class Configuration extends BaseForm | |||
{ | |||
|
|||
protected function buildForm() | |||
{ | |||
$this->formBuilder->add( | |||
"enabled-news", | |||
"checkbox", | |||
array( | |||
"label" => "Enabled News", | |||
"label_attr" => [ | |||
"for" => "enabled-news", | |||
"help" => Translator::getInstance()->trans( | |||
'Check if you want show news', | |||
[], | |||
HookAdminHome::DOMAIN_NAME | |||
) | |||
], | |||
"required" => false, | |||
"value" => HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_NEWS, 0), | |||
) | |||
); | |||
|
|||
$this->formBuilder->add( | |||
"enabled-info", | |||
"checkbox", | |||
array( | |||
"label" => "Enabled Info", | |||
"label_attr" => [ | |||
"for" => "enabled-info", | |||
"help" => Translator::getInstance()->trans( | |||
'Check if you want show info', | |||
[], | |||
HookAdminHome::DOMAIN_NAME | |||
) | |||
], | |||
"required" => false, | |||
"value" => HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_INFO, 0), | |||
) | |||
); | |||
|
|||
$this->formBuilder->add( | |||
"enabled-stats", | |||
"checkbox", | |||
array( | |||
"label" => "Enabled default Home Stats", | |||
"label_attr" => [ | |||
"for" => "enabled-stats", | |||
"help" => Translator::getInstance()->trans( | |||
'Check if you want show default Home Stats', | |||
[], | |||
HookAdminHome::DOMAIN_NAME | |||
) | |||
], | |||
"required" => false, | |||
"value" => HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_STATS, 0), | |||
) | |||
); | |||
|
|||
|
|||
$this->formBuilder->add( | |||
"enabled-sales", | |||
"checkbox", | |||
array( | |||
"label" => "Enabled Sales Statistics", | |||
"label_attr" => [ | |||
"for" => "enabled-sales", | |||
"help" => Translator::getInstance()->trans( | |||
'Check if you want show sales stats', | |||
[], | |||
HookAdminHome::DOMAIN_NAME | |||
) | |||
], | |||
"required" => false, | |||
"value" => HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_SALES, 0), | |||
) | |||
); | |||
} | |||
|
|||
public function getName() | |||
{ | |||
return "hookadminhomeconfigform"; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
<?php | |||
namespace HookAdminHome\Hook; | |||
|
|||
use Thelia\Core\Event\Hook\HookRenderEvent; | |||
use Thelia\Core\Hook\BaseHook; | |||
|
|||
class HookAdminManager extends BaseHook | |||
{ | |||
public function onModuleConfiguration(HookRenderEvent $event) | |||
{ | |||
$event->add( | |||
$this->render("admin-home-config.html") | |||
); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.