Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev/core#1000) Fixes contact's displayname not appearing in membership edit, if no registered email is found #14438

Merged
merged 1 commit into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions CRM/Contact/BAO/Contact/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,34 @@ class CRM_Contact_BAO_Contact_Location {
* Array of display_name, email, location type and location id if found, or (null,null,null, null)
*/
public static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID = NULL) {
$params = [
'location_type_id' => $locationTypeID,
$params = array(
'contact_id' => $id,
'return' => ['contact_id.display_name', 'email', 'location_type_id', 'id'],
];
'return' => array('display_name', 'email.email'),
'api.Email.get' => array(
'location_type_id' => $locationTypeID,
'sequential' => 0,
'return' => array('email', 'location_type_id', 'id'),
),
);
if ($isPrimary) {
$params['is_primary'] = 1;
$params['api.Email.get']['is_primary'] = 1;
}
$emails = civicrm_api3('Email', 'get', $params);

if ($emails['count'] > 0) {
$email = reset($emails['values']);
return [$email['contact_id.display_name'], $email['email'], $email['location_type_id'], $email['id']];
$contacts = civicrm_api3('Contact', 'get', $params);
if ($contacts['count'] > 0) {
$contact = reset($contacts['values']);
if ($contact['api.Email.get']['count'] > 0) {
$email = reset($contact['api.Email.get']['values']);
}
}
return [NULL, NULL, NULL, NULL];
$returnParams = array(
(isset($contact['display_name'])) ? $contact['display_name'] : NULL,
(isset($email['email'])) ? $email['email'] : NULL,
(isset($email['location_type_id'])) ? $email['location_type_id'] : NULL,
(isset($email['id'])) ? $email['id'] : NULL,
);

return $returnParams;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1623,4 +1623,18 @@ public function testUpdateProfileLocationLeak() {
$this->contactDelete($contactId);
}

/**
* Test that contact details are still displayed if no email is present.
*
* @throws \Exception
*/
public function testContactEmailDetailsWithNoPrimaryEmail() {
$params = $this->contactParams();
unset($params['email']);
$contact = CRM_Contact_BAO_Contact::create($params);
$contactId = $contact->id;
$result = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactId);
$this->assertEquals([$contact->display_name, NULL, NULL, NULL], $result);
}

}