$missingGreetingParams = [];
foreach ($allGreetingParams as $greetingIndex => $greetingParam) {
+ if (!empty($params[$greetingIndex . '_custom']) && empty($params[$greetingParam])) {
+ $params[$greetingParam] = CRM_Core_PseudoConstant::getKey('CRM_Contact_BAO_Contact', $greetingParam, 'Customized');
+ }
// An empty string means NULL
if (($params[$greetingParam] ?? NULL) === '') {
$params[$greetingParam] = 'null';
$addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address');
$customFields = $customFields + $addressCustomFields;
- //if a Custom Email Greeting, Custom Postal Greeting or Custom Addressee is mapped, and no "Greeting / Addressee Type ID" is provided, then automatically set the type = Customized, CRM-4575
- $elements = [
- 'email_greeting_custom' => 'email_greeting',
- 'postal_greeting_custom' => 'postal_greeting',
- 'addressee_custom' => 'addressee',
- ];
- foreach ($elements as $k => $v) {
- if (array_key_exists($k, $params) && !(array_key_exists($v, $params))) {
- $label = key(CRM_Core_OptionGroup::values($v, TRUE, NULL, NULL, 'AND v.name = "Customized"'));
- $params[$v] = $label;
- }
- }
-
//format date first
$session = CRM_Core_Session::singleton();
$dateType = $session->get("dateTypes");
if (array_key_exists($key, $locationFields)) {
continue;
}
- if (in_array($key, [
- 'email_greeting',
- 'postal_greeting',
- 'addressee',
- ])) {
- // CRM-4575, need to null custom
- if ($params["{$key}_id"] != 4) {
- $params["{$key}_custom"] = 'null';
- }
- unset($params[$key]);
- }
- else {
+
+ if (1) {
if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
$custom_params = ['id' => $contact['id'], 'return' => $key];
$getValue = civicrm_api3('Contact', 'getvalue', $custom_params);
$this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']);
}
+ /**
+ * Test the greeting fields update sensibly.
+ */
+ public function testGreetingUpdates(): void {
+ $contactID = $this->individualCreate();
+ $greetingFields = ['email_greeting_id:name', 'email_greeting_display', 'email_greeting_custom'];
+ $currentGreetings = $this->callAPISuccessGetSingle('Contact', ['id' => $contactID, 'version' => 4, 'return' => $greetingFields]);
+ $this->assertEquals('Dear {contact.first_name}', $currentGreetings['email_greeting_id:name']);
+ // Change to customized greeting.
+ $this->callAPISuccess('Contact', 'create', [
+ 'id' => $contactID,
+ 'email_greeting_id' => 'Customized',
+ 'email_greeting_custom' => 'Howdy',
+ ]);
+ $currentGreetings = $this->callAPISuccessGetSingle('Contact', ['version' => 4, 'id' => $contactID, 'return' => $greetingFields]);
+ $this->assertEquals('Customized', $currentGreetings['email_greeting_id:name']);
+ $this->assertEquals('Howdy', $currentGreetings['email_greeting_custom']);
+ $this->assertEquals('Howdy', $currentGreetings['email_greeting_display']);
+
+ // Change back to standard, check email_greeting_custom set to NULL.
+ $this->callAPISuccess('Contact', 'create', [
+ 'id' => $contactID,
+ 'email_greeting_id' => 'Dear {contact.first_name}',
+ ]);
+ $currentGreetings = $this->callAPISuccessGetSingle('Contact', ['id' => $contactID, 'version' => 4, 'return' => $greetingFields]);
+ $this->assertNull($currentGreetings['email_greeting_custom']);
+
+ $this->callAPISuccess('Contact', 'create', [
+ 'id' => $contactID,
+ 'email_greeting_custom' => 'Howdy',
+ ]);
+ $currentGreetings = $this->callAPISuccessGetSingle('Contact', ['version' => 4, 'id' => $contactID, 'return' => $greetingFields]);
+ $this->assertEquals('Customized', $currentGreetings['email_greeting_id:name']);
+ $this->assertEquals('Howdy', $currentGreetings['email_greeting_custom']);
+ $this->assertEquals('Howdy', $currentGreetings['email_greeting_display']);
+ }
+
/**
* Test Address parameters
*