// Define default template dir on tree class
This commit is contained in:
1 parent
c9a2410c57
commit
afaeb15b7d
4 files changed
+53
-11
No files matched your search
@@ -245,7 +245,7 @@ class HelperFormCore extends Helper
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function renderAssoShop($params, $disable_shared = false)
|
public function renderAssoShop($disable_shared = false, $template_directory = null)
|
||||||
{
|
{
|
||||||
if (!Shop::isFeatureActive())
|
if (!Shop::isFeatureActive())
|
||||||
return;
|
return;
|
||||||
@@ -288,6 +288,8 @@ class HelperFormCore extends Helper
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
$tree = new HelperTreeShops('shop-tree', 'Shops');
|
$tree = new HelperTreeShops('shop-tree', 'Shops');
|
||||||
|
if (isset($template_directory))
|
||||||
|
$tree->setTemplateDirectory($template_directory);
|
||||||
$tree->setSelectedShops($assos);
|
$tree->setSelectedShops($assos);
|
||||||
$tree->setAttribute('table', $this->table);
|
$tree->setAttribute('table', $this->table);
|
||||||
return $tree->render();
|
return $tree->render();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class TreeCore
|
|||||||
if (!isset($this->_toolbar))
|
if (!isset($this->_toolbar))
|
||||||
$this->setToolbar(new TreeToolbarCore());
|
$this->setToolbar(new TreeToolbarCore());
|
||||||
|
|
||||||
$this->getToolbar()->setActions($value);
|
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->setActions($value);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class TreeCore
|
|||||||
if (!isset($this->_toolbar))
|
if (!isset($this->_toolbar))
|
||||||
$this->setToolbar(new TreeToolbarCore());
|
$this->setToolbar(new TreeToolbarCore());
|
||||||
|
|
||||||
return $this->getToolbar()->getActions();
|
return $this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->getActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAttribute($name, $value)
|
public function setAttribute($name, $value)
|
||||||
@@ -293,7 +293,7 @@ class TreeCore
|
|||||||
if (!isset($this->_toolbar))
|
if (!isset($this->_toolbar))
|
||||||
$this->setToolbar(new TreeToolbarCore());
|
$this->setToolbar(new TreeToolbarCore());
|
||||||
|
|
||||||
$this->getToolbar()->addAction($action);
|
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->addAction($action);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,12 +40,13 @@ class TreeToolbarCore implements ITreeToolbarCore
|
|||||||
return $this->render();
|
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');
|
throw new PrestaShopException('Action value must be an traversable array');
|
||||||
|
|
||||||
$this->_actions = $value;
|
foreach($actions as $action)
|
||||||
|
$this->addAction($action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActions()
|
public function getActions()
|
||||||
@@ -165,6 +166,9 @@ class TreeToolbarCore implements ITreeToolbarCore
|
|||||||
if (!isset($this->_actions))
|
if (!isset($this->_actions))
|
||||||
$this->_actions = array();
|
$this->_actions = array();
|
||||||
|
|
||||||
|
if (isset($this->_template_directory))
|
||||||
|
$action->setTemplateDirectory($this->getTemplateDirectory());
|
||||||
|
|
||||||
$this->_actions[] = $action;
|
$this->_actions[] = $action;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,13 +155,49 @@ abstract class TreeToolbarButtonCore
|
|||||||
public function getTemplateDirectory()
|
public function getTemplateDirectory()
|
||||||
{
|
{
|
||||||
if (!isset($this->_template_directory))
|
if (!isset($this->_template_directory))
|
||||||
$this->_template_directory = $this->_normalizeDirectory(
|
$this->_template_directory = $this->_normalizeDirectory(self::DEFAULT_TEMPLATE_DIRECTORY);
|
||||||
$this->getContext()->smarty->getTemplateDir(0)
|
|
||||||
.self::DEFAULT_TEMPLATE_DIRECTORY);
|
|
||||||
|
|
||||||
return $this->_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)
|
public function hasAttribute($name)
|
||||||
{
|
{
|
||||||
return (isset($this->_attributes)
|
return (isset($this->_attributes)
|
||||||
@@ -171,7 +207,7 @@ abstract class TreeToolbarButtonCore
|
|||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return $this->getContext()->smarty->createTemplate(
|
return $this->getContext()->smarty->createTemplate(
|
||||||
$this->getTemplateDirectory().$this->getTemplate(),
|
$this->getTemplateFile($this->getTemplate()),
|
||||||
$this->getContext()->smarty
|
$this->getContext()->smarty
|
||||||
)->assign($this->getAttributes())->fetch();
|
)->assign($this->getAttributes())->fetch();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user