fix PHP 8.0 TypeError: Api\Accounts::username(): Argument #1 ($account_id) must be of type ?int, string given

new method for account link-title not throwing an error, for non-numeric arguments and therefore stalling all titles
This commit is contained in:
Ralf Becker 2021-11-08 12:22:41 +01:00
parent 9638bddaac
commit fa67fc24d7
2 changed files with 21 additions and 2 deletions

View File

@ -612,6 +612,20 @@ class Accounts
$account['account_firstname'] , $account['account_lastname'], $account_id);
}
/**
* Return formatted username for Links, does NOT throw if $account_id is not int
*
* @param $account_id
*/
static function title($account_id)
{
if (empty($account_id) || !is_numeric($account_id) && !($id = self::getInstance()->name2id($account_id)))
{
return '#'.$account_id;
}
return self::username($id ?? $account_id);
}
/**
* Format an email address according to the system standard
*

View File

@ -154,7 +154,7 @@ class Link extends Link\Storage
'name' => 'Accounts',
'icon' => 'addressbook/accounts',
'query' => 'EGroupware\\Api\\Accounts::link_query',
'title' => 'EGroupware\\Api\\Accounts::username',
'title' => 'EGroupware\\Api\\Accounts::title',
'view' => array('menuaction'=>'addressbook.addressbook_ui.view','ajax'=>'true'),
'view_id' => 'account_id'
),
@ -914,7 +914,12 @@ class Link extends Link\Storage
}
else
{
$title = self::title($app,$id); // no titles method --> fallback to query each link separate
try {
$title = self::title($app, $id); // no titles method --> fallback to query each link separate
}
catch (\Throwable $e) {
$title = lang('Error').': '.$e->getMessage();
}
}
}
$titles[$id] = $title;