* Addressbook: allow keeping custom fileAs value (LDAP: displayname) by adding it as first option

This commit is contained in:
ralf 2022-03-29 10:16:24 +03:00
parent 20d3394e2b
commit 49e7aab2cc
2 changed files with 16 additions and 5 deletions

View File

@ -2922,6 +2922,9 @@ class addressbook_ui extends addressbook_bo
$ret = array('doublicates' => array(), 'msg' => null);
// set not returned n_fileas value, to keep custom fileas value
$values['n_fileas'] = $this->fileas($values, $values['fileas_type']);
// if email changed, check for doublicates
if (in_array($name, array('email', 'email_home')) && in_array('contact_'.$name, $fields))
{

View File

@ -509,13 +509,14 @@ class Contacts extends Contacts\Storage
{
foreach($this->fileas_types as $type)
{
if ($this->fileas($contact,$type) == $file_as)
if ($this->fileas($contact,$type) === $file_as)
{
return $type;
}
}
}
return $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0];
// if none of our types matches, but a non-empty value is set, keep it
return $file_as ?: $this->prefs['fileas_default'] ?: $this->fileas_types[0];
}
/**
@ -558,9 +559,16 @@ class Contacts extends Contacts\Storage
{
if ($contact[$name]) $labels[$name] = $contact[$name];
}
$found = false;
foreach($this->fileas_types as $fileas_type)
{
$options[$fileas_type] = $this->fileas($labels,$fileas_type);
$options[$fileas_type] = $value = $this->fileas($labels,$fileas_type);
$found = $found || $value === $contact['n_fileas'];
}
// if we have a custom fileAs, add it as first option to keep it
if (!empty($contact['n_fileas']) && !$found)
{
$options = array_merge([$contact['n_fileas'] => lang('Custom').': '.$contact['n_fileas']], $options);
}
return $options;
}