allow to use alternate location name "hook_location", if app needs original name "location", like eg. calendar

This commit is contained in:
Ralf Becker 2015-10-13 07:08:10 +00:00
parent 9f1b92aa1d
commit 887cd00c4c

View File

@ -94,7 +94,7 @@ class hooks
function process($args, $order = array(), $no_permission_check = False) function process($args, $order = array(), $no_permission_check = False)
{ {
//echo "<p>".__METHOD__.'('.array2string($args).','.array2string($order).','.array2string($no_permission_check).")</p>\n"; //echo "<p>".__METHOD__.'('.array2string($args).','.array2string($order).','.array2string($no_permission_check).")</p>\n";
$location = is_array($args) ? $args['location'] : $args; $location = is_array($args) ? (isset($args['hook_location']) ? $args['hook_location'] : $args['location']) : $args;
$hooks = $this->locations[$location]; $hooks = $this->locations[$location];
if (!isset($hooks) || empty($hooks)) return array(); // not a single app implements that hook if (!isset($hooks) || empty($hooks)) return array(); // not a single app implements that hook
@ -123,16 +123,16 @@ class hooks
* @param string|array $args location-name as string or array with keys location, appname and * @param string|array $args location-name as string or array with keys location, appname and
* further data to be passed to the hook, if its a new method-hook * further data to be passed to the hook, if its a new method-hook
* @param string $appname name of the app, which's hook to execute, if empty the current app is used * @param string $appname name of the app, which's hook to execute, if empty the current app is used
* @param boolean $no_permission_check if True execute all hooks, not only the ones a user has rights to * @param boolean $no_permission_check =false if True execute all hooks, not only the ones a user has rights to
* $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo) * $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
* @param boolean $try_unregisterd If true, try to include old file-hook anyway (for setup) * @param boolean $try_unregistered =false If true, try to include old file-hook anyway (for setup)
* @return mixed False if no hook exists, True if old hook exists and whatever the new method-hook returns (can be True or False too!). * @return mixed False if no hook exists, True if old hook exists and whatever the new method-hook returns (can be True or False too!).
*/ */
function single($args, $appname = '', $no_permission_check = False,$try_unregistered = False) function single($args, $appname = '', $no_permission_check = False,$try_unregistered = False)
{ {
//echo "<p>hooks::single(".array2string($args).",'$appname','$no_permission_check','$try_unregistered')</p>\n"; //echo "<p>hooks::single(".array2string($args).",'$appname','$no_permission_check','$try_unregistered')</p>\n";
if (!is_array($args)) $args = array('location' => $args); if (!is_array($args)) $args = array('location' => $args);
$location = $args['location']; $location = isset($args['hook_location']) ? $args['hook_location'] : $args['location'];
if (!$appname) if (!$appname)
{ {