module template inclusion
This commit is contained in:
@@ -56,7 +56,7 @@ class HttpException extends BaseAction implements EventSubscriberInterface
|
|||||||
$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(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||||
|
|
||||||
//$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView());
|
//$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView());
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class BaseAdminController extends BaseController
|
|||||||
$parser = $this->container->get("thelia.parser");
|
$parser = $this->container->get("thelia.parser");
|
||||||
|
|
||||||
// Define the template that should be used
|
// Define the template that should be used
|
||||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath());
|
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate());
|
||||||
|
|
||||||
return $parser;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class BaseFrontController extends BaseController
|
|||||||
$parser = $this->container->get("thelia.parser");
|
$parser = $this->container->get("thelia.parser");
|
||||||
|
|
||||||
// Define the template that should be used
|
// Define the template that should be used
|
||||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||||
|
|
||||||
return $parser;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class ViewListener implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
$parser = $this->container->get('thelia.parser');
|
$parser = $this->container->get('thelia.parser');
|
||||||
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
$parser->setTemplate(TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||||
$request = $this->container->get('request');
|
$request = $this->container->get('request');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use Thelia\Core\Template\ParserInterface;
|
|||||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||||
use Thelia\Core\Template\ParserContext;
|
use Thelia\Core\Template\ParserContext;
|
||||||
|
use Thelia\Core\Template\TemplateDefinition;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Core\Template\TemplateHelper;
|
use Thelia\Core\Template\TemplateHelper;
|
||||||
|
|
||||||
@@ -23,13 +24,15 @@ use Thelia\Core\Template\TemplateHelper;
|
|||||||
*/
|
*/
|
||||||
class SmartyParser extends Smarty implements ParserInterface
|
class SmartyParser extends Smarty implements ParserInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public $plugins = array();
|
public $plugins = array();
|
||||||
|
|
||||||
protected $request;
|
protected $request;
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
protected $parserContext;
|
protected $parserContext;
|
||||||
|
|
||||||
|
protected $backOfficeTemplateDirectories = array();
|
||||||
|
protected $frontOfficeTemplateDirectories = array();
|
||||||
|
|
||||||
protected $template = "";
|
protected $template = "";
|
||||||
|
|
||||||
protected $status = 200;
|
protected $status = 200;
|
||||||
@@ -101,15 +104,59 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTemplate($template_path_from_template_base)
|
public function addBackOfficeTemplateDirectory($templateName, $templateDirectory, $key)
|
||||||
{
|
{
|
||||||
$this->template = $template_path_from_template_base;
|
$this->backOfficeTemplateDirectories[$templateName][$key] = $templateDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
$this->addTemplateDir(THELIA_TEMPLATE_DIR.$this->template, 0);
|
public function addFrontOfficeTemplateDirectory($templateName, $templateDirectory, $key)
|
||||||
|
{
|
||||||
|
$this->frontOfficeTemplateDirectories[$templateName][$key] = $templateDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
$config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs';
|
/**
|
||||||
|
* @param TemplateDefinition $templateDefinition
|
||||||
|
*/
|
||||||
|
public function setTemplate(TemplateDefinition $templateDefinition)
|
||||||
|
{
|
||||||
|
$this->template = $templateDefinition->getPath();
|
||||||
|
|
||||||
$this->setConfigDir($config_dir);
|
/* init template directories */
|
||||||
|
$this->setTemplateDir(array());
|
||||||
|
|
||||||
|
/* add main template directory */
|
||||||
|
$this->addTemplateDir(THELIA_TEMPLATE_DIR . $this->template, 0);
|
||||||
|
|
||||||
|
/* define config directory */
|
||||||
|
$configDirectory = THELIA_TEMPLATE_DIR . $this->template . '/configs';
|
||||||
|
$this->setConfigDir($configDirectory);
|
||||||
|
|
||||||
|
/* add modules template directories */
|
||||||
|
switch($templateDefinition->getType()) {
|
||||||
|
case TemplateDefinition::FRONT_OFFICE:
|
||||||
|
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
||||||
|
if(isset($this->frontOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
||||||
|
foreach($this->frontOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
||||||
|
$this->addTemplateDir($directory, $key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TemplateDefinition::BACK_OFFICE:
|
||||||
|
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
||||||
|
if(isset($this->backOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
||||||
|
foreach($this->backOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
||||||
|
$this->addTemplateDir($directory, $key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TemplateDefinition::PDF:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplate()
|
public function getTemplate()
|
||||||
|
|||||||
@@ -54,14 +54,20 @@ class TemplateDefinition
|
|||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
if ($type == self::BACK_OFFICE)
|
switch($type) {
|
||||||
$this->path = self::BACK_OFFICE_SUBDIR . $name;
|
case TemplateDefinition::FRONT_OFFICE:
|
||||||
else if ($type == self::PDF)
|
$this->path = self::FRONT_OFFICE_SUBDIR . $name;
|
||||||
$this->path = self::PDF_SUBDIR . $name;
|
break;
|
||||||
else if ($type == self::FRONT_OFFICE)
|
case TemplateDefinition::BACK_OFFICE:
|
||||||
$this->path = self::FRONT_OFFICE_SUBDIR . $name;
|
$this->path = self::BACK_OFFICE_SUBDIR . $name;
|
||||||
else
|
break;
|
||||||
$this->path = $name;
|
case TemplateDefinition::PDF:
|
||||||
|
$this->path = self::PDF_SUBDIR . $name;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->path = $name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ class TemplateHelper
|
|||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TemplateDefinition
|
||||||
|
*/
|
||||||
public function getActivePdfTemplate() {
|
public function getActivePdfTemplate() {
|
||||||
return new TemplateDefinition(
|
return new TemplateDefinition(
|
||||||
ConfigQuery::read('active-pdf-template', 'default'),
|
ConfigQuery::read('active-pdf-template', 'default'),
|
||||||
@@ -53,6 +56,9 @@ class TemplateHelper
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TemplateDefinition
|
||||||
|
*/
|
||||||
public function getActiveAdminTemplate() {
|
public function getActiveAdminTemplate() {
|
||||||
return new TemplateDefinition(
|
return new TemplateDefinition(
|
||||||
ConfigQuery::read('active-admin-template', 'default'),
|
ConfigQuery::read('active-admin-template', 'default'),
|
||||||
@@ -60,6 +66,9 @@ class TemplateHelper
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TemplateDefinition
|
||||||
|
*/
|
||||||
public function getActiveFrontTemplate() {
|
public function getActiveFrontTemplate() {
|
||||||
return new TemplateDefinition(
|
return new TemplateDefinition(
|
||||||
ConfigQuery::read('active-front-template', 'default'),
|
ConfigQuery::read('active-front-template', 'default'),
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ use Thelia\Core\Bundle;
|
|||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Config\DatabaseConfiguration;
|
use Thelia\Config\DatabaseConfiguration;
|
||||||
use Thelia\Config\DefinePropel;
|
use Thelia\Config\DefinePropel;
|
||||||
|
use Thelia\Core\Template\TemplateDefinition;
|
||||||
use Thelia\Core\TheliaContainerBuilder;
|
use Thelia\Core\TheliaContainerBuilder;
|
||||||
use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
|
use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -126,7 +127,6 @@ class Thelia extends Kernel
|
|||||||
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
||||||
|
|
||||||
$translationDirs = array();
|
$translationDirs = array();
|
||||||
$templateDirs = array();
|
|
||||||
$parser = $container->getDefinition('thelia.parser');
|
$parser = $container->getDefinition('thelia.parser');
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
|
||||||
@@ -151,9 +151,54 @@ class Thelia extends Kernel
|
|||||||
$translationDirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
|
/* is there a front-office template directory ? */
|
||||||
//$templateDirs[$code] = $dir;
|
$frontOfficeModuleTemplateDirectory = sprintf("%s%s%stemplates%s%s", THELIA_MODULE_DIR, $code, DS, DS, TemplateDefinition::FRONT_OFFICE_SUBDIR);
|
||||||
$parser->addMethodCall('addTemplateDir', array($dir, $code));
|
if (is_dir($frontOfficeModuleTemplateDirectory)) {
|
||||||
|
try {
|
||||||
|
$moduleFrontOfficeTemplateBrowser = new \DirectoryIterator($frontOfficeModuleTemplateDirectory);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* browse the directory */
|
||||||
|
foreach ($moduleFrontOfficeTemplateBrowser as $moduleFrontOfficeTemplateContent) {
|
||||||
|
/* is it a directory which is not . or .. ? */
|
||||||
|
if ($moduleFrontOfficeTemplateContent->isDir() && !$moduleFrontOfficeTemplateContent->isDot()) {
|
||||||
|
$parser->addMethodCall(
|
||||||
|
'addFrontOfficeTemplateDirectory',
|
||||||
|
array(
|
||||||
|
$moduleFrontOfficeTemplateContent->getFilename(),
|
||||||
|
$frontOfficeModuleTemplateDirectory,
|
||||||
|
$code,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* is there a back-office template directory ? */
|
||||||
|
$backOfficeModuleTemplateDirectory = sprintf("%s%s%stemplates%s%s", THELIA_MODULE_DIR, $code, DS, DS, TemplateDefinition::BACK_OFFICE_SUBDIR);
|
||||||
|
if (is_dir($backOfficeModuleTemplateDirectory)) {
|
||||||
|
try {
|
||||||
|
$moduleBackOfficeTemplateBrowser = new \DirectoryIterator($backOfficeModuleTemplateDirectory);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* browse the directory */
|
||||||
|
foreach ($moduleBackOfficeTemplateBrowser as $moduleBackOfficeTemplateContent) {
|
||||||
|
/* is it a directory which is not . or .. ? */
|
||||||
|
if ($moduleBackOfficeTemplateContent->isDir() && !$moduleBackOfficeTemplateContent->isDot()) {
|
||||||
|
$parser->addMethodCall(
|
||||||
|
'addBackOfficeTemplateDirectory',
|
||||||
|
array(
|
||||||
|
$moduleBackOfficeTemplateContent->getFilename(),
|
||||||
|
$backOfficeModuleTemplateDirectory,
|
||||||
|
$code,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
// TODO: process module configuration exception
|
// TODO: process module configuration exception
|
||||||
|
|||||||
Reference in New Issue
Block a user