From 2ec25b9e451ebe6d31a5a4a0832811b28722a4b3 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 14 Jan 2021 15:59:03 +0200 Subject: [PATCH] allow to format link-registry entries "add", "edit", ... as "url" parameter for actions --- api/src/Link.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/api/src/Link.php b/api/src/Link.php index 6ebdfba2be..137fae0c28 100644 --- a/api/src/Link.php +++ b/api/src/Link.php @@ -1125,9 +1125,11 @@ class Link extends Link\Storage * * @param string $app app-name * @param string $name name / key in the registry, eg. 'view' + * @param boolean|array|string|int $url_id format entries like "add", "edit", "view" for actions "url" incl. an ID + * array to add arbitray parameter eg. ['some_id' => '$id'] * @return boolean|string false if $app is not registered, otherwise string with the value for $name */ - static function get_registry($app,$name) + static function get_registry($app, $name, $url_id=false) { $reg = self::$app_register[$app]; @@ -1157,6 +1159,25 @@ class Link extends Link\Storage } } + // format as action url + if ($url_id && isset($reg[$name]) && is_array($reg[$name])) + { + $params = $reg[$name]; + if (isset($reg[$name.'_id'])) + { + $params[$reg[$name.'_id']] = $url_id === true ? '$id' : $url_id; + } + if (is_array($url_id)) + { + $params += $url_id; + } + foreach($params as $name => $value) + { + $str .= (!empty($str) ? '&' : '').$name.'='.$value; + } + return $str; + } + return isset($reg) ? $reg[$name] : false; }