// Added Helper::createTemplate()

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9888 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-11-04 13:31:09 +00:00
parent c46fd00276
commit 74bb9d88c8
10 changed files with 85 additions and 102 deletions
+3 -7
View File
@@ -1230,7 +1230,7 @@ class AdminControllerCore extends Controller
$helper->shopLink = $this->shopLink;
$helper->shopLinkType = $this->shopLinkType;
$helper->identifier = $this->identifier;
$helper->tpl_folder = $this->tpl_folder;
$helper->override_folder = $this->tpl_folder;
$helper->token = $this->token;
$helper->specificConfirmDelete = $this->specificConfirmDelete;
$helper->imageType = $this->imageType;
@@ -1254,9 +1254,7 @@ class AdminControllerCore extends Controller
{
$this->getlanguages();
$helper = new HelperForm($this);
// Check if form template has been overriden
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'form.tpl'))
$helper->setTpl($this->tpl_folder.'form.tpl');
$helper->override_folder = $this->tpl_folder;
$helper->currentIndex = self::$currentIndex;
$helper->token = $this->token;
$helper->table = $this->table;
@@ -1288,9 +1286,7 @@ class AdminControllerCore extends Controller
if ($this->options && is_array($this->options))
{
$helper = new HelperOptions();
// Check if form template has been overriden
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'options.tpl'))
$helper->setTpl($this->tpl_folder.'options.tpl');
$helper->override_folder = $this->tpl_folder;
$helper->id = $this->id;
$helper->token = $this->token;
$helper->shopLinkType = $this->shopLinkType;
+34 -11
View File
@@ -42,29 +42,53 @@ class HelperCore
public $no_back = false;
public $context;
/** @var string Helper tpl folder */
public $base_folder;
/** @var string Controller tpl folder */
public $override_folder;
/**
* @var string filename, then smartyTemplate object
* @var smartyTemplate base template object
*/
protected $tpl = 'content.tpl';
protected $tpl;
/**
* @var string base template name
*/
protected $base_tpl = 'content.tpl';
public $tpl_vars = array();
public function __construct()
{
$this->context = Context::getContext();
$this->tpl = $this->context->smarty->createTemplate($this->tpl);
}
public function setTpl($tpl)
}
/*public function setTpl($tpl)
{
if (file_exists($this->context->smarty->template_dir[0].'/'.$tpl))
$this->tpl = $this->context->smarty->createTemplate($tpl);
$this->tpl = $this->createTemplate($tpl);
}*/
/**
* Create a template from the override file, else from the base file.
*
* @param string $tpl_name filename
* @return Template
*/
public function createTemplate($tpl_name)
{
// Overrides exists?
if ($this->override_folder && file_exists($this->context->smarty->template_dir[0].$this->override_folder.$tpl_name))
return $this->context->smarty->createTemplate($this->override_folder.$tpl_name);
return $this->context->smarty->createTemplate($this->base_folder.$tpl_name);
}
/**
* default behaviour for helper is to return a tpl fetched
*
*
* @return void
*/
public function generate()
@@ -73,7 +97,6 @@ class HelperCore
return $this->tpl->fetch();
}
/**
*
* @param type $trads values of translations keys
+7 -6
View File
@@ -27,9 +27,7 @@
class HelperFormCore extends Helper
{
public $id;
public $first_call = true;
public $toolbar = true;
@@ -39,9 +37,7 @@ class HelperFormCore extends Helper
*
*/
protected $fields_form = array();
public $fields_value = array();
public $table;
/**
@@ -51,12 +47,16 @@ class HelperFormCore extends Helper
public $submit_action = '';
public $token;
public $languages = null;
public $default_form_language = null;
public $allow_employee_form_lang = null;
protected $tpl = 'helper/form/form.tpl';
public function __construct()
{
$this->base_folder = 'helper/form/';
$this->base_tpl = 'form.tpl';
parent::__construct();
}
public function generateForm($fields_form)
{
@@ -66,6 +66,7 @@ class HelperFormCore extends Helper
public function generate()
{
$this->tpl = $this->createTemplate($this->base_tpl);
if ($this->submit_action == '')
$this->submit_action = 'submitAdd'.$this->table;
+25 -29
View File
@@ -55,9 +55,6 @@ class HelperListCore extends Helper
protected $deleted = 0;
/** @var string Folder of controller */
public $tpl_folder;
/** @var array $cache_lang use to cache texts in current language */
public static $cache_lang = array();
@@ -81,10 +78,9 @@ class HelperListCore extends Helper
/** @var boolean Content line is clickable if true */
public $no_link = false;
protected $tpl = 'helper/list/list.tpl';
protected $header_tpl = 'helper/list/list_header.tpl';
protected $content_tpl = 'helper/list/list_content.tpl';
protected $footer_tpl = 'helper/list/list_footer.tpl';
protected $header_tpl = 'list_header.tpl';
protected $content_tpl = 'list_content.tpl';
protected $footer_tpl = 'list_footer.tpl';
/** @var array list of required actions for each list row */
public $actions = array();
@@ -113,25 +109,18 @@ class HelperListCore extends Helper
/** @var boolean ask for simple header : no filters, no paginations and no sorting */
public $simple_header = false;
/**
* @var bool
* Usage : Set the value to false if you want to simply display the back button
*/
public $no_back = true;
public function __construct()
{
$this->base_folder = 'helper/list/';
$this->base_tpl = 'list.tpl';
parent::__construct();
$smarty = $this->context->smarty;
$controller = $this->context->controller;
// handle template overriding (smarty 3 template inheritance)
if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_header.tpl'))
$this->header_tpl = $controller->tpl_folder.'list_header.tpl';
if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_content.tpl'))
$this->content_tpl = $controller->tpl_folder.'list_content.tpl';
if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_footer.tpl'))
$this->footer_tpl = $controller->tpl_folder.'list_footer.tpl';
$this->header_tpl = $this->context->smarty->createTemplate($this->header_tpl);
$this->content_tpl = $this->context->smarty->createTemplate($this->content_tpl);
$this->footer_tpl = $this->context->smarty->createTemplate($this->footer_tpl);
}
/**
@@ -152,6 +141,12 @@ class HelperListCore extends Helper
$this->displayWarning($this->l('Bad SQL query'));
return false;
}
$this->tpl = $this->createTemplate($this->base_tpl);
$this->header_tpl = $this->createTemplate($this->header_tpl);
$this->content_tpl = $this->createTemplate($this->content_tpl);
$this->footer_tpl = $this->createTemplate($this->footer_tpl);
$this->_list = $list;
$this->fieldsDisplay = $fields_display;
@@ -162,6 +157,7 @@ class HelperListCore extends Helper
/* Close list table and submit button */
$tpl_vars['footer'] = $this->displayListFooter();
$this->tpl->assign($tpl_vars);
return parent::generate();
}
@@ -178,7 +174,7 @@ class HelperListCore extends Helper
*/
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{
$tpl_enable = $this->context->smarty->createTemplate('helper/list/list_action_enable.tpl');
$tpl_enable = $this->createTemplate('list_action_enable.tpl');
$tpl_enable->assign(array(
'enabled' => (bool)$value,
'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
@@ -353,7 +349,7 @@ class HelperListCore extends Helper
*/
protected function displayDuplicateLink($token = null, $id)
{
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_duplicate.tpl');
$tpl = $this->createTemplate('list_action_duplicate.tpl');
if (!array_key_exists('Duplicate', self::$cache_lang))
self::$cache_lang['Duplicate'] = $this->l('Duplicate');
@@ -395,7 +391,7 @@ class HelperListCore extends Helper
*/
protected function displayDetailsLink($token = null, $id)
{
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_details.tpl');
$tpl = $this->createTemplate('list_action_details.tpl');
if (!array_key_exists('Details', self::$cache_lang))
self::$cache_lang['Details'] = $this->l('Details');
$tpl->assign(array(
@@ -412,7 +408,7 @@ class HelperListCore extends Helper
*/
protected function displayViewLink($token = null, $id)
{
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_view.tpl');
$tpl = $this->createTemplate('list_action_view.tpl');
if (!array_key_exists('View', self::$cache_lang))
self::$cache_lang['View'] = $this->l('View');
@@ -430,7 +426,7 @@ class HelperListCore extends Helper
*/
protected function displayEditLink($token = null, $id)
{
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_edit.tpl');
$tpl = $this->createTemplate('list_action_edit.tpl');
if (!array_key_exists('Edit', self::$cache_lang))
self::$cache_lang['Edit'] = $this->l('Edit');
@@ -449,7 +445,7 @@ class HelperListCore extends Helper
*/
protected function displayDeleteLink($token = null, $id)
{
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_delete.tpl');
$tpl = $this->createTemplate('list_action_delete.tpl');
if (!array_key_exists('Delete', self::$cache_lang))
self::$cache_lang['Delete'] = $this->l('Delete');
+7 -1
View File
@@ -42,7 +42,12 @@ class HelperOptionsCore extends Helper
public $fields_value = array();
public $tpl = 'helper/options/options.tpl';
public function __construct()
{
$this->base_folder = 'helper/options/';
$this->base_tpl = 'options.tpl';
parent::__construct();
}
/**
* Generate a form for options
@@ -51,6 +56,7 @@ class HelperOptionsCore extends Helper
*/
public function generateOptions($option_list)
{
$this->tpl = $this->createTemplate($this->base_tpl);
$tab = Tab::getTab($this->context->language->id, $this->id);
if (!isset($languages))
$languages = Language::getLanguages(false);