summaryrefslogtreecommitdiff
path: root/app/Helper
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-08-13 18:41:01 -0400
committerFrederic Guillot <fred@kanboard.net>2016-08-13 18:41:01 -0400
commit010199e8f846f6c0b4f23336338bfda17ec04901 (patch)
treebce51661cd43034ed2d6bb6caf04574767a712ec /app/Helper
parent2ebe8b32728c341ec16e1197fe2e12d32ddd5de5 (diff)
Add the possibility to attach template hooks with a callback
Diffstat (limited to 'app/Helper')
-rw-r--r--app/Helper/HookHelper.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/Helper/HookHelper.php b/app/Helper/HookHelper.php
index 418c55a0..e43cfdfd 100644
--- a/app/Helper/HookHelper.php
+++ b/app/Helper/HookHelper.php
@@ -46,6 +46,12 @@ class HookHelper extends Base
foreach ($this->hook->getListeners($hook) as $params) {
if (! empty($params['variables'])) {
$variables = array_merge($variables, $params['variables']);
+ } elseif (! empty($params['callable'])) {
+ $result = call_user_func_array($params['callable'], $variables);
+
+ if (is_array($result)) {
+ $variables = array_merge($variables, $result);
+ }
}
$buffer .= $this->template->render($params['template'], $variables);
@@ -72,4 +78,25 @@ class HookHelper extends Base
return $this;
}
+
+ /**
+ * Attach a template to a hook with a callable
+ *
+ * Arguments passed to the callback are the one passed to the hook
+ *
+ * @access public
+ * @param string $hook
+ * @param string $template
+ * @param callable $callable
+ * @return $this
+ */
+ public function attachCallable($hook, $template, callable $callable)
+ {
+ $this->hook->on($hook, array(
+ 'template' => $template,
+ 'callable' => $callable,
+ ));
+
+ return $this;
+ }
}