Skip to content

Commit 14e488f

Browse files
authored
Merge pull request #3 from NicolasBarbey/feature/i18n
Feature/i18n
2 parents 5435b24 + 95af0f8 commit 14e488f

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

Config/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<language>en_US</language>
1414
<language>fr_FR</language>
1515
</languages>
16-
<version>2.0</version>
16+
<version>2.0.1</version>
1717
<authors>
1818
<author>
1919
<name>Tom Pradat</name>

Controller/Configuration.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function saveAction(){
3737
try {
3838
$vform = $this->validateForm($form);
3939
$data = $vform->getData();
40+
$lang = $this->getRequest()->getSession()->get('thelia.admin.edition.lang');
4041

41-
GoogleTagManager::setConfigValue('googletagmanager_gtmId',$data['gtmId']);
42+
GoogleTagManager::setConfigValue('googletagmanager_gtmId', $data['gtmId'], $lang->getlocale());
4243
} catch (\Exception $e) {
4344
$this->setupFormErrorContext(
4445
$this->getTranslator()->trans("Syntax error"),

Form/Configuration.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ protected function buildForm()
2828
{
2929
$form = $this->formBuilder;
3030

31-
$value = GoogleTagManager::getConfigValue('googletagmanager_gtmId');
31+
$lang = $this->getRequest()->getSession()->get('thelia.admin.edition.lang');
32+
$value = GoogleTagManager::getConfigValue('googletagmanager_gtmId', null, $lang->getLocale());
3233
$form->add(
3334
"gtmId",
3435
"text",

Hook/FrontHook.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use GoogleTagManager\GoogleTagManager;
1717
use Thelia\Core\Event\Hook\HookRenderEvent;
1818
use Thelia\Core\Hook\BaseHook;
19+
use Thelia\Model\Base\LangQuery;
1920
use Thelia\Model\ConfigQuery;
2021

2122
/**
@@ -26,7 +27,8 @@
2627
class FrontHook extends BaseHook
2728
{
2829
public function onMainHeadTop(HookRenderEvent $event){
29-
$value = GoogleTagManager::getConfigValue('googletagmanager_gtmId');
30+
$lang = $this->getLang();
31+
$value = GoogleTagManager::getConfigValue('googletagmanager_gtmId', null, $lang->getLocale());
3032
if ("" != $value){
3133
$event->add(
3234
"<!-- Google Tag Manager -->".
@@ -40,7 +42,8 @@ public function onMainHeadTop(HookRenderEvent $event){
4042
}
4143
}
4244
public function onMainBodyTop(HookRenderEvent $event){
43-
$value = GoogleTagManager::getConfigValue('googletagmanager_gtmId');
45+
$lang = $this->getLang();
46+
$value = GoogleTagManager::getConfigValue('googletagmanager_gtmId', null, $lang->getLocale());
4447
if ("" != $value){
4548
$event->add("<!-- Google Tag Manager (noscript) -->".
4649
"<noscript><iframe src='https://www.googletagmanager.com/ns.html?id=".$value."' ".
@@ -49,4 +52,13 @@ public function onMainBodyTop(HookRenderEvent $event){
4952
);
5053
}
5154
}
55+
56+
protected function getLang()
57+
{
58+
$lang = $this->getRequest()->getSession()->get("thelia.current.lang");
59+
if (null === $lang){
60+
$lang = LangQuery::create()->filterByByDefault(1)->findOne();
61+
}
62+
return $lang;
63+
}
5264
}

templates/backOffice/default/module_configuration.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
<div class="form-container">
99
<div class="col-md-12">
10-
10+
{include file="includes/inner-form-toolbar.html"
11+
hide_submit_buttons = true
12+
}
1113
{form name="googletagmanager.configuration.form"}
1214
<form method="POST" id="googletagmanager-form" action="{url path="/admin/module/googletagmanager/save"}" {form_enctype} class="clearfix">
1315

0 commit comments

Comments
 (0)