refactor how to assign template to parser
This commit is contained in:
@@ -42,7 +42,8 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand
|
|||||||
'Config',
|
'Config',
|
||||||
'Model',
|
'Model',
|
||||||
'Loop',
|
'Loop',
|
||||||
'AdminIncludes'
|
'AdminIncludes',
|
||||||
|
'templates',
|
||||||
);
|
);
|
||||||
|
|
||||||
protected function verifyExistingModule()
|
protected function verifyExistingModule()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
<argument type="service" id="request" />
|
<argument type="service" id="request" />
|
||||||
<argument type="service" id="event_dispatcher"/>
|
<argument type="service" id="event_dispatcher"/>
|
||||||
<argument type="service" id="thelia.parser.context"/>
|
<argument type="service" id="thelia.parser.context"/>
|
||||||
<argument >false</argument> <!-- Template name, or false -->
|
|
||||||
<argument >%kernel.environment%</argument>
|
<argument >%kernel.environment%</argument>
|
||||||
<argument >%kernel.debug%</argument>
|
<argument >%kernel.debug%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class BaseAdminController extends BaseController
|
|||||||
$parser = $this->container->get("thelia.parser");
|
$parser = $this->container->get("thelia.parser");
|
||||||
|
|
||||||
// Define the template thant shoud be used
|
// Define the template thant shoud be used
|
||||||
$parser->setTemplate($template ?: ConfigQuery::read('base-admin-template', 'admin/default'));
|
$parser->addTemplateDir($template ?: ConfigQuery::read('base-admin-template', 'admin/default'), 'default');
|
||||||
|
|
||||||
return $parser;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,13 +37,12 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param EventDispatcherInterface $dispatcher
|
* @param EventDispatcherInterface $dispatcher
|
||||||
* @param ParserContext $parserContext
|
* @param ParserContext $parserContext
|
||||||
* @param bool $template
|
|
||||||
* @param string $env
|
* @param string $env
|
||||||
* @param bool $debug
|
* @param bool $debug
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
|
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
|
||||||
$template = false, $env = "prod", $debug = false)
|
$env = "prod", $debug = false)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
$this->setCompileDir($compile_dir);
|
$this->setCompileDir($compile_dir);
|
||||||
$this->setCacheDir($cache_dir);
|
$this->setCacheDir($cache_dir);
|
||||||
|
|
||||||
$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
|
//$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
|
||||||
|
|
||||||
$this->debugging = $debug;
|
$this->debugging = $debug;
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,10 @@ class Thelia extends Kernel
|
|||||||
|
|
||||||
if (defined("THELIA_INSTALL_MODE") === false) {
|
if (defined("THELIA_INSTALL_MODE") === false) {
|
||||||
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
||||||
$translator = $container->getDefinition('thelia.translator');
|
|
||||||
$dirs = array();
|
$translationDirs = array();
|
||||||
|
$templateDirs = array();
|
||||||
|
$parser = $container->getDefinition('thelia.parser');
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -138,46 +140,60 @@ class Thelia extends Kernel
|
|||||||
$defintion
|
$defintion
|
||||||
);
|
);
|
||||||
|
|
||||||
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
|
$code = ucfirst($module->getCode());
|
||||||
|
|
||||||
|
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . $code . "/Config"));
|
||||||
$loader->load("config.xml");
|
$loader->load("config.xml");
|
||||||
|
|
||||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) {
|
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/I18n")) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
|
||||||
|
//$templateDirs[$code] = $dir;
|
||||||
|
$parser->addMethodCall('addTemplateDir', array($dir, $code));
|
||||||
}
|
}
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
// FIXME: process module configuration exception
|
// TODO: process module configuration exception
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load translation from templates
|
//Load translation from templates
|
||||||
//core translation
|
//core translation
|
||||||
$dirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n";
|
$translationDirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n";
|
||||||
|
|
||||||
//admin template
|
//admin template
|
||||||
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
|
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
//front template
|
//front template
|
||||||
$template = ConfigQuery::getActiveTemplate();
|
$template = ConfigQuery::getActiveTemplate();
|
||||||
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
|
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dirs) {
|
if ($translationDirs) {
|
||||||
$finder = Finder::create()
|
$this->loadTranslation($container, $translationDirs);
|
||||||
->files()
|
|
||||||
->depth(0)
|
|
||||||
->in($dirs);
|
|
||||||
|
|
||||||
foreach ($finder as $file) {
|
|
||||||
list($locale, $format) = explode('.', $file->getBaseName(), 2);
|
|
||||||
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadTranslation(ContainerBuilder $container, array $dirs)
|
||||||
|
{
|
||||||
|
$translator = $container->getDefinition('thelia.translator');
|
||||||
|
|
||||||
|
$finder = Finder::create()
|
||||||
|
->files()
|
||||||
|
->depth(0)
|
||||||
|
->in($dirs);
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
list($locale, $format) = explode('.', $file->getBaseName(), 2);
|
||||||
|
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* initialize session in Request object
|
* initialize session in Request object
|
||||||
|
|||||||
Reference in New Issue
Block a user