Skip to content
Permalink
Browse files

Merge pull request #2657 from zawaze/Feat/Add_Option_HookadminHome

Add option to show/Hide stats bloc
  • Loading branch information...
gillesbourgeat committed Mar 28, 2019
2 parents 637cdfa + bb9d43b commit fd13b0668b11227ffc62ad54495633d50960e31b
@@ -4,7 +4,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">

<forms>
<form name="hookadminhome.config.form" class="HookAdminHome\Form\Configuration" />
</forms>

<hooks>
<hook id="hookadminhome.configuration.hook" class="HookAdminHome\Hook\HookAdminManager" scope="request">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfiguration" />
</hook>

<hook id="hookadminhome.hook.css">
<tag name="hook.event_listener" event="main.head-css" type="back" templates="css:assets/css/home.css" />
</hook>
@@ -27,6 +27,6 @@
</author>
</authors>
<type>classic</type>
<thelia>2.4.0</thelia>
<thelia>2.3.4</thelia>
<stability>prod</stability>
</module>
@@ -20,4 +20,9 @@
<default key="not-logged">1</default>
</route>



<route id="admin.home.config" path="/admin/module/HookAdminHome/configure" methods="post">
<default key="_controller">HookAdminHome\Controller\ConfigurationController::editConfiguration</default>
</route>
</routes>
@@ -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;
}
}
@@ -151,4 +151,6 @@ protected function testHexColor($key, $default)
return preg_match('/^#[a-f0-9]{6}$/i', $hexColor) ? $hexColor : $default;
}
}
@@ -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";
}
}
@@ -26,46 +26,59 @@ class AdminHook extends BaseHook
{
public function blockStatistics(HookRenderEvent $event)
{
$event->add($this->render('block-statistics.html'));
if (1 == HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_STATS, 1)) {
$event->add($this->render('block-statistics.html'));
}
$event->add($this->render('hook-admin-home-config.html'));
}
public function blockStatisticsJs(HookRenderEvent $event)
{
$event->add($this->render('block-statistics-js.html'));
if (1 == HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_STATS, 1)) {
$event->add($this->render('block-statistics-js.html'));
}
}
public function blockSalesStatistics(HookRenderBlockEvent $event)
{
$content = trim($this->render("block-sales-statistics.html"));
if (!empty($content)) {
$event->add([
"id" => "block-sales-statistics",
"title" => $this->trans("Sales statistics", [], HookAdminHome::DOMAIN_NAME),
"content" => $content
]);
if (1 == HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_SALES, 1)) {
$content = trim($this->render("block-sales-statistics.html"));
if (!empty($content)) {
$event->add([
"id" => "block-sales-statistics",
"title" => $this->trans("Sales statistics", [], HookAdminHome::DOMAIN_NAME),
"content" => $content
]);
}
}
}
public function blockNews(HookRenderBlockEvent $event)
{
$content = trim($this->render("block-news.html"));
if (!empty($content)) {
$event->add([
"id" => "block-news",
"content" => $content
]);
if (1 == HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_NEWS, 1)) {
$content = trim($this->render("block-news.html"));
if (!empty($content)) {
$event->add([
"id" => "block-news",
"content" => $content
]);
}
}
}
public function blockTheliaInformation(HookRenderBlockEvent $event)
{
$content = trim($this->render("block-thelia-information.html"));
if (!empty($content)) {
$event->add([
"id" => "block-thelia-information",
"title" => $this->trans("Thelia informations", [], HookAdminHome::DOMAIN_NAME),
"content" => $content
]);
if (1 == HookAdminHome::getConfigValue(HookAdminHome::ACTIVATE_INFO, 1)) {
$content = trim($this->render("block-thelia-information.html"));
if (!empty($content)) {
$event->add([
"id" => "block-thelia-information",
"title" => $this->trans("Thelia informations", [], HookAdminHome::DOMAIN_NAME),
"content" => $content
]);
}
}
}
}
@@ -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")
);
}
}
@@ -12,10 +12,35 @@
namespace HookAdminHome;
use Thelia\Core\Template\TemplateDefinition;
use Thelia\Module\BaseModule;
class HookAdminHome extends BaseModule
{
/** @var string */
const DOMAIN_NAME = 'hookadminhome';
/** @var string */
const ACTIVATE_NEWS = 'activate_home_news';
/** @var string */
const ACTIVATE_SALES= 'activate_home_sales';
/** @var string */
const ACTIVATE_INFO= 'activate_home_info';
/** @var string */
const ACTIVATE_STATS= 'activate_stats';
public function getHooks()
{
return array(
array(
"type" => TemplateDefinition::BACK_OFFICE,
"code" => "hook_home_stats",
"title" => "Hook Home Stats",
"description" => "Hook to change default stats",
)
);
}
}
Oops, something went wrong.

0 comments on commit fd13b06

Please sign in to comment.
You can’t perform that action at this time.