diff --git a/core/lib/Thelia/Command/BaseModuleGenerate.php b/core/lib/Thelia/Command/BaseModuleGenerate.php index 7d487d4cc..b3286c874 100755 --- a/core/lib/Thelia/Command/BaseModuleGenerate.php +++ b/core/lib/Thelia/Command/BaseModuleGenerate.php @@ -42,7 +42,8 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand 'Config', 'Model', 'Loop', - 'AdminIncludes' + 'AdminIncludes', + 'templates', ); protected function verifyExistingModule() diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 198f9f999..5a3548a9c 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -50,7 +50,6 @@ - false %kernel.environment% %kernel.debug% diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index d34f2ce82..f820f4bf5 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -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; } diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 272f6787c..5a3665d21 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -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; diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index fafe50171..c5a4c16c3 100755 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -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