From 369de2e3d59113ecd99c0607c29cfda56dd1c904 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 27 Sep 2021 10:54:00 -0600 Subject: [PATCH] Specific ordering for contact merge placeholders also, use switch to using prefix() --- api/src/Contacts/Merge.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/api/src/Contacts/Merge.php b/api/src/Contacts/Merge.php index 0e9a496813..4c0dcf6681 100644 --- a/api/src/Contacts/Merge.php +++ b/api/src/Contacts/Merge.php @@ -275,7 +275,22 @@ class Merge extends Api\Storage\Merge */ public function get_placeholder_list($prefix = '') { - $placeholders = []; + // Specific order for these ones + $placeholders = [ + 'contact' => [], + 'details' => [ + $this->prefix($prefix, 'categories', '{') => lang('Category path'), + $this->prefix($prefix, 'note', '{') => $this->contacts->contact_fields['note'], + $this->prefix($prefix, 'id', '{') => $this->contacts->contact_fields['id'], + $this->prefix($prefix, 'owner', '{') => $this->contacts->contact_fields['owner'], + $this->prefix($prefix, 'private', '{') => $this->contacts->contact_fields['private'], + $this->prefix($prefix, 'cat_id', '{') => $this->contacts->contact_fields['cat_id'], + ], + + ]; + + // Iterate through the list & switch groups as we go + // Hopefully a little better than assigning each field to a group $group = 'contact'; foreach($this->contacts->contact_fields as $name => $label) { @@ -299,24 +314,27 @@ class Merge extends Api\Storage\Merge case 'email_home': $group = 'email'; break; - case 'url': + case 'freebusy_uri': $group = 'details'; } - $placeholders[$group]["{{" . ($prefix ? $prefix . '/' : '') . $name . "}}"] = $label; - if($name == 'cat_id') + $marker = $this->prefix($prefix, $name, '{'); + if(!array_filter($placeholders, function ($a) use ($marker) { - $placeholders[$group]["{{" . ($prefix ? $prefix . '/' : '') . $name . "}}"] = lang('Category path'); + return array_key_exists($marker, $a); + })) + { + $placeholders[$group][$marker] = $label; } } // Correctly formatted address by country / preference - $placeholders['business']['{{' . ($prefix ? $prefix . '/' : '') . 'adr_one_formatted}}'] = "Formatted business address"; - $placeholders['private']['{{' . ($prefix ? $prefix . '/' : '') . 'adr_two_formatted}}'] = "Formatted private address"; + $placeholders['business'][$this->prefix($prefix, 'adr_one_formatted', '{')] = "Formatted business address"; + $placeholders['private'][$this->prefix($prefix, 'adr_two_formatted', '{')] = "Formatted private address"; $group = 'customfields'; foreach($this->contacts->customfields as $name => $field) { - $placeholders[$group]["{{" . ($prefix ? $prefix . '/' : '') . $name . "}}"] = $field['label']; + $placeholders[$group][$this->prefix($prefix, $name, '{')] = $field['label']; } return $placeholders; }