Placeholder dialog: Allow & show general fields

This commit is contained in:
nathan 2021-09-27 11:09:38 -06:00
parent 369de2e3d5
commit eb57294146
2 changed files with 58 additions and 5 deletions

View File

@ -64,7 +64,7 @@ class Placeholder extends Etemplate\Widget
if(is_null($apps))
{
$apps = ['addressbook', 'user'];
$apps = ['addressbook', 'user', 'general'];
}
foreach($apps as $appname)
@ -75,6 +75,9 @@ class Placeholder extends Etemplate\Widget
case 'user':
$list = $merge->get_user_placeholder_list();
break;
case 'general':
$list = $merge->get_common_placeholder_list();
break;
default:
$list = $merge->get_placeholder_list();
break;

View File

@ -2644,17 +2644,67 @@ abstract class Merge
);
}
/**
* Get a list of common placeholders
*
* @param string $prefix
*/
public function get_common_placeholder_list($prefix = '')
{
$placeholders = [
'URLs' => [],
'Egroupware links' => [],
'General' => [],
'Repeat' => [],
'Commands' => []
];
// Iterate through the list & switch groups as we go
// Hopefully a little better than assigning each field to a group
$group = 'URLs';
foreach($this->get_common_replacements() as $name => $label)
{
if(in_array($name, array('user/n_fn', 'user/account_lid')))
{
continue;
} // don't show them, they're in 'User'
switch($name)
{
case 'links':
$group = 'Egroupware links';
break;
case 'date':
$group = 'General';
break;
case 'pagerepeat':
$group = 'Repeat';
break;
case 'IF fieldname':
$group = 'Commands';
}
$marker = $this->prefix($prefix, $name, '{');
if(!array_filter($placeholders, function ($a) use ($marker)
{
return array_key_exists($marker, $a);
}))
{
$placeholders[$group][$marker] = $label;
}
}
return $placeholders;
}
/**
* Get a list of placeholders for the current user
*/
public function get_user_placeholder_list($prefix = '')
{
$contacts = new Api\Contacts\Merge();
$replacements = $contacts->get_placeholder_list(($prefix ? $prefix . '/' : '') . 'user');
unset($replacements['details']['{{' . ($prefix ? $prefix . '/' : '') . 'user/account_id}}']);
$replacements = $contacts->get_placeholder_list($this->prefix($prefix, 'user'));
unset($replacements['details'][$this->prefix($prefix, 'user/account_id', '{')]);
$replacements['account'] = [
'{{' . ($prefix ? $prefix . '/' : '') . 'user/account_id}}' => 'Account ID',
'{{' . ($prefix ? $prefix . '/' : '') . 'user/account_lid}}' => 'Login ID'
$this->prefix($prefix, 'user/account_id', '{') => 'Account ID',
$this->prefix($prefix, 'user/account_lid', '{') => 'Login ID'
];
return $replacements;