// change to BO template override

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9268 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-10-12 13:37:04 +00:00
parent 98bf6af495
commit 3bf92f6fa2
2 changed files with 29 additions and 14 deletions
+25 -12
View File
@@ -151,6 +151,7 @@ class AdminControllerCore extends Controller
protected $action; protected $action;
protected $display; protected $display;
protected $_includeContainer = true; protected $_includeContainer = true;
protected $tpl_folder;
/** @var bool Redirect or not ater a creation */ /** @var bool Redirect or not ater a creation */
protected $_redirect = true; protected $_redirect = true;
@@ -202,6 +203,10 @@ class AdminControllerCore extends Controller
if (!Shop::isMultiShopActivated()) if (!Shop::isMultiShopActivated())
$this->shopLinkType = ''; $this->shopLinkType = '';
// Get the name of the folder containing the custom tpl files
$this->tpl_folder = strtolower($controller[5]).substr($controller, 6);
$this->tpl_folder = Tools::toUnderscoreCase($this->tpl_folder).'/';
} }
/** /**
@@ -690,20 +695,16 @@ class AdminControllerCore extends Controller
$this->context->smarty->assign('content', $this->content); $this->context->smarty->assign('content', $this->content);
$this->context->smarty->assign('meta_title', $this->meta_title); $this->context->smarty->assign('meta_title', $this->meta_title);
$class_name = get_class($this); // Template override
$class_name = strtolower($class_name[5]).substr($class_name, 6); $tpl = $this->tpl_folder.'content.tpl';
$class_name = Tools::toUnderscoreCase(substr($class_name, 0, -10)); $tpl_action = $this->tpl_folder.$this->display.'.tpl';
$tpl = $class_name.'/content.tpl';
$tpl_action = $class_name.'/'.$this->display.'.tpl';
// Check if action template has been override // Check if action template has been override
if (file_exists($this->context->smarty->template_dir.'/'.$tpl_action)) if (file_exists($this->context->smarty->template_dir.'/'.$tpl_action))
$this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action));
// Check if content template has been override // Check if content template has been override
if (file_exists($this->context->smarty->template_dir.'/'.$tpl)) if (file_exists($this->context->smarty->template_dir.'/'.$tpl))
$page = $this->context->smarty->fetch($tpl); $page = $this->context->smarty->fetch($tpl);
else else
$page = $this->context->smarty->fetch($this->template); $page = $this->context->smarty->fetch($this->template);
@@ -899,15 +900,17 @@ class AdminControllerCore extends Controller
*/ */
public function initContent() public function initContent()
{ {
if ($this->display == 'edit') if ($this->display == 'edit' || $this->display == 'add')
{ {
if (!($obj = $this->loadObject(true))) if (!($obj = $this->loadObject(true)))
return; return;
if (isset($this->fields_form)) if (isset($this->fields_form))
{ {
$helper = new HelperForm(); $helper = new HelperForm();
// Check if form template has been overriden
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'form.tpl'))
$helper->tpl = $this->tpl_folder.'form.tpl';
$helper::$currentIndex = self::$currentIndex; $helper::$currentIndex = self::$currentIndex;
$helper->token = $this->token; $helper->token = $this->token;
$helper->table = $this->table; $helper->table = $this->table;
@@ -916,7 +919,7 @@ class AdminControllerCore extends Controller
$this->content .= $helper->generateForm($this->fields_form); $this->content .= $helper->generateForm($this->fields_form);
} }
else else
//@TODO à supprimer // TODO delete when all forms use the helper
$this->content .= $this->displayForm(); $this->content .= $this->displayForm();
if ($this->tabAccess['view']) if ($this->tabAccess['view'])
@@ -931,6 +934,13 @@ class AdminControllerCore extends Controller
{ {
$this->getList($this->context->language->id); $this->getList($this->context->language->id);
$helper = new HelperList(); $helper = new HelperList();
// Check if list templates have been overriden
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'list_header.tpl'))
$helper->header_tpl = $this->tpl_folder.'list_header.tpl';
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'list_content.tpl'))
$helper->header_tpl = $this->tpl_folder.'list_content.tpl';
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'list_footer.tpl'))
$helper->header_tpl = $this->tpl_folder.'list_footer.tpl';
$helper->view = $this->view; $helper->view = $this->view;
$helper->edit = $this->edit; $helper->edit = $this->edit;
$helper->delete = $this->delete; $helper->delete = $this->delete;
@@ -1030,6 +1040,9 @@ class AdminControllerCore extends Controller
return self::translate($string, $class, $addslashes, $htmlentities); return self::translate($string, $class, $addslashes, $htmlentities);
} }
/**
* Init context and dependencies, handles POST and GET
*/
public function init() public function init()
{ {
// ob_start(); // ob_start();
@@ -1171,7 +1184,7 @@ class AdminControllerCore extends Controller
else if (isset($_GET['add'.$this->table])) else if (isset($_GET['add'.$this->table]))
{ {
$this->action = 'new'; $this->action = 'new';
$this->display = 'edit'; $this->display = 'add';
} }
else if (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table])) else if (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table]))
{ {
+4 -2
View File
@@ -35,7 +35,7 @@ class HelperFormCore extends Helper
/** /**
* @var array of forms fields * @var array of forms fields
* Usage : * Usage :
* *
*/ */
protected $fields_form = array(); protected $fields_form = array();
@@ -47,6 +47,8 @@ class HelperFormCore extends Helper
public static $currentIndex; public static $currentIndex;
public $tpl = 'form.tpl';
public function generateForm($fields_form) public function generateForm($fields_form)
{ {
$this->fields_form = $fields_form; $this->fields_form = $fields_form;
@@ -85,7 +87,7 @@ class HelperFormCore extends Helper
'requiredFields' => $this->getFieldsRequired() 'requiredFields' => $this->getFieldsRequired()
)); ));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/form.tpl'); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl);
} }
public function getFieldsRequired() public function getFieldsRequired()