// Define default template dir on tree class

This commit is contained in:
Jerome Nadaud
2013-11-13 20:10:13 +01:00
parent c9a2410c57
commit afaeb15b7d
4 changed files with 53 additions and 11 deletions
+3 -1
View File
@@ -245,7 +245,7 @@ class HelperFormCore extends Helper
*
* @return string
*/
public function renderAssoShop($params, $disable_shared = false)
public function renderAssoShop($disable_shared = false, $template_directory = null)
{
if (!Shop::isFeatureActive())
return;
@@ -288,6 +288,8 @@ class HelperFormCore extends Helper
}*/
$tree = new HelperTreeShops('shop-tree', 'Shops');
if (isset($template_directory))
$tree->setTemplateDirectory($template_directory);
$tree->setSelectedShops($assos);
$tree->setAttribute('table', $this->table);
return $tree->render();
+3 -3
View File
@@ -61,7 +61,7 @@ class TreeCore
if (!isset($this->_toolbar))
$this->setToolbar(new TreeToolbarCore());
$this->getToolbar()->setActions($value);
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->setActions($value);
return $this;
}
@@ -70,7 +70,7 @@ class TreeCore
if (!isset($this->_toolbar))
$this->setToolbar(new TreeToolbarCore());
return $this->getToolbar()->getActions();
return $this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->getActions();
}
public function setAttribute($name, $value)
@@ -293,7 +293,7 @@ class TreeCore
if (!isset($this->_toolbar))
$this->setToolbar(new TreeToolbarCore());
$this->getToolbar()->addAction($action);
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->addAction($action);
return $this;
}
+7 -3
View File
@@ -40,12 +40,13 @@ class TreeToolbarCore implements ITreeToolbarCore
return $this->render();
}
public function setActions($value)
public function setActions($actions)
{
if (!is_array($value) && !$value instanceof Traversable)
if (!is_array($actions) && !$actions instanceof Traversable)
throw new PrestaShopException('Action value must be an traversable array');
$this->_actions = $value;
foreach($actions as $action)
$this->addAction($action);
}
public function getActions()
@@ -165,6 +166,9 @@ class TreeToolbarCore implements ITreeToolbarCore
if (!isset($this->_actions))
$this->_actions = array();
if (isset($this->_template_directory))
$action->setTemplateDirectory($this->getTemplateDirectory());
$this->_actions[] = $action;
return $this;
}
+40 -4
View File
@@ -155,13 +155,49 @@ abstract class TreeToolbarButtonCore
public function getTemplateDirectory()
{
if (!isset($this->_template_directory))
$this->_template_directory = $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0)
.self::DEFAULT_TEMPLATE_DIRECTORY);
$this->_template_directory = $this->_normalizeDirectory(self::DEFAULT_TEMPLATE_DIRECTORY);
return $this->_template_directory;
}
public function getTemplateFile($template)
{
if (preg_match_all('/((?:^|[A-Z])[a-z]+)/', get_class($this->getContext()->controller), $matches) !== FALSE)
$controllerName = strtolower($matches[0][1]);
if ($this->getContext()->controller instanceof ModuleAdminController)
return $this->_normalizeDirectory(
$this->getContext()->controller->getTemplatePath())
.$this->getTemplateDirectory().$template;
else if ($this->getContext()->controller instanceof AdminController
&& isset($controllerName) && file_exists($this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0)).'controllers'
.DIRECTORY_SEPARATOR
.$controllerName
.DIRECTORY_SEPARATOR
.$this->getTemplateDirectory().$template))
return $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0)).'controllers'
.DIRECTORY_SEPARATOR
.$controllerName
.DIRECTORY_SEPARATOR
.$this->getTemplateDirectory().$template;
else if (file_exists($this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(1))
.$this->getTemplateDirectory().$template))
return $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(1))
.$this->getTemplateDirectory().$template;
else if (file_exists($this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0))
.$this->getTemplateDirectory().$template))
return $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0))
.$this->getTemplateDirectory().$template;
else
return $this->getTemplateDirectory().$template;
}
public function hasAttribute($name)
{
return (isset($this->_attributes)
@@ -171,7 +207,7 @@ abstract class TreeToolbarButtonCore
public function render()
{
return $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getTemplate(),
$this->getTemplateFile($this->getTemplate()),
$this->getContext()->smarty
)->assign($this->getAttributes())->fetch();
}