$serialize = CRM_Core_BAO_CustomField::isSerialized($field);
if ($serialize) {
- if ($field['data_type'] != 'Country' && $field['data_type'] != 'StateProvince') {
+ if ($field['data_type'] != 'Country' && $field['data_type'] != 'StateProvince' && $field['data_type'] != 'ContactReference') {
$defaults[$elementName] = [];
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($field['id'], $inactiveNeeded);
if ($viewMode) {
CRM_Utils_Array::formatArrayKeys($value);
$checkedValue = $value;
}
+ // Serialized values from db
+ elseif ($value === '' || strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
+ $checkedValue = CRM_Utils_Array::explodePadded($value);
+ }
+ // Comma-separated values e.g. from a select2 widget during reload on form error
else {
- $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1));
+ $checkedValue = explode(',', $value);
}
foreach ($checkedValue as $val) {
if ($val) {
elseif ($field['data_type'] == 'Money' &&
$field['html_type'] == 'Text'
) {
- $defaults[$elementName] = CRM_Utils_Money::format($value, NULL, '%a');
+ $defaults[$elementName] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($value);
}
else {
$defaults[$elementName] = $value;
$details[$groupID][$values['id']]['editable'] = TRUE;
}
// also return contact reference contact id if user has view all or edit all contacts perm
- if ((CRM_Core_Permission::check('view all contacts') ||
- CRM_Core_Permission::check('edit all contacts'))
- &&
- $details[$groupID][$values['id']]['fields'][$k]['field_data_type'] ==
- 'ContactReference'
+ if ($details[$groupID][$values['id']]['fields'][$k]['field_data_type'] === 'ContactReference'
+ && CRM_Core_Permission::check([['view all contacts', 'edit all contacts']])
) {
- $details[$groupID][$values['id']]['fields'][$k]['contact_ref_id'] = $values['data'] ?? NULL;
+ $details[$groupID][$values['id']]['fields'][$k]['contact_ref_links'] = [];
+ $path = CRM_Contact_DAO_Contact::getEntityPaths()['view'];
+ foreach (CRM_Utils_Array::explodePadded($values['data'] ?? []) as $contactId) {
+ $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'display_name');
+ if ($displayName) {
+ $url = CRM_Utils_System::url(str_replace('[id]', $contactId, $path));
+ $details[$groupID][$values['id']]['fields'][$k]['contact_ref_links'][] = '<a href="' . $url . '" title="' . htmlspecialchars(ts('View Contact')) . '">' .
+ $displayName . '</a>';
+ }
+ }
}
}
}
$details[$groupID][0]['collapse_display'] = $group['collapse_display'] ?? NULL;
$details[$groupID][0]['collapse_adv_display'] = $group['collapse_adv_display'] ?? NULL;
$details[$groupID][0]['style'] = $group['style'] ?? NULL;
- $details[$groupID][0]['fields'][$k] = ['field_title' => CRM_Utils_Array::value('label', $properties)];
+ $details[$groupID][0]['fields'][$k] = ['field_title' => $properties['label'] ?? NULL];
}
}
}