diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-08-13 18:41:01 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-08-13 18:41:01 -0400 |
commit | 010199e8f846f6c0b4f23336338bfda17ec04901 (patch) | |
tree | bce51661cd43034ed2d6bb6caf04574767a712ec /app | |
parent | 2ebe8b32728c341ec16e1197fe2e12d32ddd5de5 (diff) |
Add the possibility to attach template hooks with a callback
Diffstat (limited to 'app')
-rw-r--r-- | app/Helper/HookHelper.php | 27 |
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; + } } |