Une première version d'une version permettant d'avoir des templates différents suivant la langue.
A creuser mais peut-être pas besoin de TemplateSwitcher et de CustomSwitchTemplate, et qu'il suffirait de rajouter juste du Smarty dans layout.tpl et index.html
This commit is contained in:
13
local/modules/CustomSwitchTemplate/Config/config.xml
Normal file
13
local/modules/CustomSwitchTemplate/Config/config.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<config xmlns="http://thelia.net/schema/dic/config"
|
||||
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">
|
||||
|
||||
<services>
|
||||
<service id="customswitchtemplate.listener" class="CustomSwitchTemplate\EventListeners\CustomSwitchTemplateListener">
|
||||
<argument type="service" id="request_stack"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
</services>
|
||||
</config>
|
||||
37
local/modules/CustomSwitchTemplate/Config/module.xml
Normal file
37
local/modules/CustomSwitchTemplate/Config/module.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
|
||||
<fullnamespace>CustomSwitchTemplate\CustomSwitchTemplate</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>Change template according to user's language, to hide some features (placing order, ...) to non-french users</title>
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>Change le template suivant la langue, pour proposer une version "bridée" du site aux clients non français</title>
|
||||
</descriptive>
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
<language>fr_FR</language>
|
||||
</languages>
|
||||
<version>1.0.0</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name>Laurent LE CORRE</name>
|
||||
<company>TheCoreDev</company>
|
||||
<email>laurent@thecoredev.fr</email>
|
||||
</author>
|
||||
</authors>
|
||||
<type>classic</type>
|
||||
<!--
|
||||
module dependencies
|
||||
<required>
|
||||
<module version=">=0.1">Front</module>
|
||||
<module version="~1.0">HookCart</module>
|
||||
<module version=">0.2">HookSearch</module>
|
||||
</required>
|
||||
-->
|
||||
<thelia>2.3.0</thelia>
|
||||
<stability>other</stability>
|
||||
<mandatory>0</mandatory>
|
||||
<hidden>0</hidden>
|
||||
</module>
|
||||
9
local/modules/CustomSwitchTemplate/Config/thelia.sql
Normal file
9
local/modules/CustomSwitchTemplate/Config/thelia.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
INSERT INTO config (name, value, secured, hidden, created_at, updated_at)
|
||||
VALUES('alternative-front-template', 'sterivein_sans_commande', 0, 0, '2024-01-09 12:00:00.000', NULL);
|
||||
|
||||
INSERT INTO config_i18n
|
||||
(id, locale, title, description, chapo, postscriptum)
|
||||
VALUES(LAST_INSERT_ID(), 'fr_FR', 'Module CustomSwitchTemplate - Nom du template sans commande', NULL, NULL, NULL);
|
||||
INSERT INTO config_i18n
|
||||
(id, locale, title, description, chapo, postscriptum)
|
||||
VALUES(LAST_INSERT_ID(), 'en_US', 'Module CustomSwitchTemplate - Name of alternative template', NULL, NULL, NULL);
|
||||
39
local/modules/CustomSwitchTemplate/CustomSwitchTemplate.php
Normal file
39
local/modules/CustomSwitchTemplate/CustomSwitchTemplate.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 CustomSwitchTemplate;
|
||||
|
||||
use AdminComment\Model\AdminCommentQuery;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Thelia\Install\Database;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
class CustomSwitchTemplate extends BaseModule
|
||||
{
|
||||
/** @var string */
|
||||
const DOMAIN_NAME = 'customswitchtemplate';
|
||||
|
||||
/*
|
||||
* You may now override BaseModuleInterface methods, such as:
|
||||
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
|
||||
*
|
||||
* Have fun !
|
||||
*/
|
||||
public function postActivation(ConnectionInterface $con = null)
|
||||
{
|
||||
if (null == ConfigQuery::read('alternative-front-template')) {
|
||||
$database = new Database($con->getWrappedConnection());
|
||||
$database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace CustomSwitchTemplate\EventListeners;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\Event\ResponseEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class CustomSwitchTemplateListener implements EventSubscriberInterface
|
||||
{
|
||||
public function checkTemplateSwitch(RequestEvent $event): void
|
||||
{
|
||||
Tlog::getInstance()->debug("CustomSwitchTemplate : test");
|
||||
/*
|
||||
$session = $event->getRequest()->getSession();
|
||||
$locale = $session->getLang()->getLocale();
|
||||
|
||||
if ($locale === 'fr_FR') {
|
||||
$templateName = ConfigQuery::read('active-front-template', '');
|
||||
} else {
|
||||
$templateName = ConfigQuery::read('alternative-front-template', '');
|
||||
}
|
||||
|
||||
$event = (new TemplateSwitcherEvent($templateName))
|
||||
->setTemplateType(TemplateDefinition::FRONT_OFFICE);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
TemplateSwitcherEvent::SWITCH_TEMPLATE_EVENT,
|
||||
$event
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* api.
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
KernelEvents::REQUEST => ['checkTemplateSwitch', 100],
|
||||
];
|
||||
}
|
||||
}
|
||||
5
local/modules/CustomSwitchTemplate/I18n/en_US.php
Normal file
5
local/modules/CustomSwitchTemplate/I18n/en_US.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return array(
|
||||
// 'an english string' => 'The displayed english string',
|
||||
'Alternative template name' => 'Name of alternative template',
|
||||
);
|
||||
5
local/modules/CustomSwitchTemplate/I18n/fr_FR.php
Normal file
5
local/modules/CustomSwitchTemplate/I18n/fr_FR.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return array(
|
||||
// 'an english string' => 'La traduction française de la chaine',
|
||||
'Alternative template name' => 'Nom du template sans commande',
|
||||
);
|
||||
55
local/modules/CustomSwitchTemplate/Readme.md
Normal file
55
local/modules/CustomSwitchTemplate/Readme.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Custom Switch Template
|
||||
|
||||
Add a short description here. You can also add a screenshot if needed.
|
||||
|
||||
## Installation
|
||||
|
||||
### Manually
|
||||
|
||||
* Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is CustomSwitchTemplate.
|
||||
* Activate it in your thelia administration panel
|
||||
|
||||
### Composer
|
||||
|
||||
Add it in your main thelia composer.json file
|
||||
|
||||
```
|
||||
composer require your-vendor/custom-switch-template-module:~1.0
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Explain here how to use your module, how to configure it, etc.
|
||||
|
||||
## Hook
|
||||
|
||||
If your module use one or more hook, fill this part. Explain which hooks are used.
|
||||
|
||||
|
||||
## Loop
|
||||
|
||||
If your module declare one or more loop, describe them here like this :
|
||||
|
||||
[loop name]
|
||||
|
||||
### Input arguments
|
||||
|
||||
|Argument |Description |
|
||||
|--- |--- |
|
||||
|**arg1** | describe arg1 with an exemple. |
|
||||
|**arg2** | describe arg2 with an exemple. |
|
||||
|
||||
### Output arguments
|
||||
|
||||
|Variable |Description |
|
||||
|--- |--- |
|
||||
|$VAR1 | describe $VAR1 variable |
|
||||
|$VAR2 | describe $VAR2 variable |
|
||||
|
||||
### Exemple
|
||||
|
||||
Add a complete exemple of your loop
|
||||
|
||||
## Other ?
|
||||
|
||||
If you have other think to put, feel free to complete your readme as you want.
|
||||
11
local/modules/CustomSwitchTemplate/composer.json
Normal file
11
local/modules/CustomSwitchTemplate/composer.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "your-vendor/custom-switch-template-module",
|
||||
"license": "LGPL-3.0+",
|
||||
"type": "thelia-module",
|
||||
"require": {
|
||||
"thelia/installer": "~1.1"
|
||||
},
|
||||
"extra": {
|
||||
"installer-name": "CustomSwitchTemplate"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user