refactor how to assign template to parser
This commit is contained in:
@@ -42,7 +42,8 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand
|
||||
'Config',
|
||||
'Model',
|
||||
'Loop',
|
||||
'AdminIncludes'
|
||||
'AdminIncludes',
|
||||
'templates',
|
||||
);
|
||||
|
||||
protected function verifyExistingModule()
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
<argument type="service" id="request" />
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
<argument type="service" id="thelia.parser.context"/>
|
||||
<argument >false</argument> <!-- Template name, or false -->
|
||||
<argument >%kernel.environment%</argument>
|
||||
<argument >%kernel.debug%</argument>
|
||||
</service>
|
||||
|
||||
@@ -199,7 +199,7 @@ class BaseAdminController extends BaseController
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -37,13 +37,12 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
* @param Request $request
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
* @param ParserContext $parserContext
|
||||
* @param bool $template
|
||||
* @param string $env
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct(
|
||||
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
|
||||
$template = false, $env = "prod", $debug = false)
|
||||
$env = "prod", $debug = false)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
@@ -62,7 +61,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
$this->setCompileDir($compile_dir);
|
||||
$this->setCacheDir($cache_dir);
|
||||
|
||||
$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
|
||||
//$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
|
||||
|
||||
$this->debugging = $debug;
|
||||
|
||||
|
||||
@@ -123,8 +123,10 @@ class Thelia extends Kernel
|
||||
|
||||
if (defined("THELIA_INSTALL_MODE") === false) {
|
||||
$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) {
|
||||
|
||||
try {
|
||||
@@ -138,46 +140,60 @@ class Thelia extends Kernel
|
||||
$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");
|
||||
|
||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) {
|
||||
$dirs[] = $dir;
|
||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/I18n")) {
|
||||
$translationDirs[] = $dir;
|
||||
}
|
||||
|
||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
|
||||
//$templateDirs[$code] = $dir;
|
||||
$parser->addMethodCall('addTemplateDir', array($dir, $code));
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// FIXME: process module configuration exception
|
||||
// TODO: process module configuration exception
|
||||
}
|
||||
}
|
||||
|
||||
//Load translation from templates
|
||||
//core translation
|
||||
$dirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n";
|
||||
$translationDirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n";
|
||||
|
||||
//admin template
|
||||
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
|
||||
$dirs[] = $dir;
|
||||
$translationDirs[] = $dir;
|
||||
}
|
||||
|
||||
//front template
|
||||
$template = ConfigQuery::getActiveTemplate();
|
||||
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
|
||||
$dirs[] = $dir;
|
||||
$translationDirs[] = $dir;
|
||||
}
|
||||
|
||||
if ($dirs) {
|
||||
$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));
|
||||
}
|
||||
if ($translationDirs) {
|
||||
$this->loadTranslation($container, $translationDirs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user