Add user placeholders into placeholder dialog

This commit is contained in:
nathan 2021-09-22 11:15:49 -06:00
parent 9239b86cd9
commit 704b6c6dc2
3 changed files with 43 additions and 27 deletions

View File

@ -273,7 +273,7 @@ class Merge extends Api\Storage\Merge
* *
* Placeholders are grouped logically. Group key should have a user-friendly translation. * Placeholders are grouped logically. Group key should have a user-friendly translation.
*/ */
public function get_placeholder_list() public function get_placeholder_list($prefix = '')
{ {
$placeholders = []; $placeholders = [];
$group = 'contact'; $group = 'contact';
@ -302,21 +302,21 @@ class Merge extends Api\Storage\Merge
case 'url': case 'url':
$group = 'details'; $group = 'details';
} }
$placeholders[$group]["{{" . $name . "}}"] = $label; $placeholders[$group]["{{" . ($prefix ? $prefix . '/' : '') . $name . "}}"] = $label;
if($name == 'cat_id') if($name == 'cat_id')
{ {
$placeholders[$group]["{{" . $name . "}}"] = lang('Category path'); $placeholders[$group]["{{" . ($prefix ? $prefix . '/' : '') . $name . "}}"] = lang('Category path');
} }
} }
// Correctly formatted address by country / preference // Correctly formatted address by country / preference
$placeholders['business']["{{adr_one_formatted}}"] = "Formatted business address"; $placeholders['business']['{{' . ($prefix ? $prefix . '/' : '') . 'adr_one_formatted}}'] = "Formatted business address";
$placeholders['private']["{{adr_two_formatted}}"] = "Formatted private address"; $placeholders['private']['{{' . ($prefix ? $prefix . '/' : '') . 'adr_two_formatted}}'] = "Formatted private address";
$group = 'customfields'; $group = 'customfields';
foreach($this->contacts->customfields as $name => $field) foreach($this->contacts->customfields as $name => $field)
{ {
$placeholders[$group]["{{" . $name . "}}"] = $field['label']; $placeholders[$group]["{{" . ($prefix ? $prefix . '/' : '') . $name . "}}"] = $field['label'];
} }
return $placeholders; return $placeholders;
} }

View File

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

View File

@ -2620,4 +2620,20 @@ abstract class Merge
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'), 'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'),
); );
} }
/**
* 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['account'] = [
'{{' . ($prefix ? $prefix . '/' : '') . 'user/account_id}}' => 'Account ID',
'{{' . ($prefix ? $prefix . '/' : '') . 'user/account_lid}}' => 'Login ID'
];
return $replacements;
}
} }