/**
* View summary details of a contact.
+ *
+ * @throws \CRM_Core_Exception
*/
public function view() {
// Add js for tabs, in-place editing, and jstree for tags
->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')
->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
- ->addSetting(array(
- 'summaryPrint' => array('mode' => $this->_print),
- 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')),
- ));
+ ->addSetting([
+ 'summaryPrint' => ['mode' => $this->_print],
+ 'tabSettings' => ['active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')],
+ ]);
$this->assign('summaryPrint', $this->_print);
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId);
$this->assignFieldMetadataToTemplate('Contact');
$params = [];
- $defaults = [];
+ $defaults = [
+ // Set empty default values for these - they will be overwritten when the contact is
+ // loaded in CRM_Contact_BAO_Contact::retrieve if there are real values
+ // but since we are not using apiV4 they will be left unset if empty.
+ // However, the wind up assigned as smarty variables so we ensure they are set to prevent e-notices
+ // used by ContactInfo.tpl
+ 'job_title' => '',
+ 'current_employer_id' => '',
+ 'nick_name' => '',
+ 'legal_name' => '',
+ 'source' => '',
+ 'sic_code' => '',
+ 'external_identifier' => '',
+ // for CommunicationPreferences.tpl
+ 'postal_greeting_custom' => '',
+ 'email_greeting_custom' => '',
+ 'addressee_custom' => '',
+ 'communication_style_display' => '',
+ // for Demographics.tpl
+ 'age' => ['y' => '', 'm' => ''],
+ 'birth_date' => '',
+ // for Website.tpl (the others don't seem to enotice for some reason).
+ 'website' => [],
+ ];
+
+ $params['contact_id'] = $this->_contactId;
+
+ CRM_Contact_BAO_Contact::getValues(array_merge(['id' => $this->_contactId], $params), $defaults);
+ $defaults['im'] = CRM_Core_BAO_IM::getValues(['contact_id' => $params['contact_id']]);
+ $defaults['email'] = CRM_Core_BAO_Email::getValues(['contact_id' => $params['contact_id']]);
+ $defaults['openid'] = CRM_Core_BAO_OpenID::getValues(['contact_id' => $params['contact_id']]);
+ $defaults['phone'] = CRM_Core_BAO_Phone::getValues(['contact_id' => $params['contact_id']]);
+ $defaults['address'] = CRM_Core_BAO_Address::getValues(['contact_id' => $params['contact_id']], TRUE);
+ CRM_Core_BAO_Website::getValues($params, $defaults);
+ // Copy employer fields to the current_employer keys.
+ if (($defaults['contact_type'] === 'Individual') && !empty($defaults['employer_id']) && !empty($defaults['organization_name'])) {
+ $defaults['current_employer'] = $defaults['organization_name'];
+ $defaults['current_employer_id'] = $defaults['employer_id'];
+ }
- $params['id'] = $params['contact_id'] = $this->_contactId;
- $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE;
- $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE);
// Let summary page know if outbound mail is disabled so email links can be built conditionally
$mailingBackend = Civi::settings()->get('mailing_backend');
$this->assign('mailingOutboundOption', $mailingBackend['outBound_option']);
- $communicationType = array(
- 'phone' => array(
+ $communicationType = [
+ 'phone' => [
'type' => 'phoneType',
'id' => 'phone_type',
'daoName' => 'CRM_Core_DAO_Phone',
'fieldName' => 'phone_type_id',
- ),
- 'im' => array(
+ ],
+ 'im' => [
'type' => 'IMProvider',
'id' => 'provider',
'daoName' => 'CRM_Core_DAO_IM',
'fieldName' => 'provider_id',
- ),
- 'website' => array(
+ ],
+ 'website' => [
'type' => 'websiteType',
'id' => 'website_type',
'daoName' => 'CRM_Core_DAO_Website',
'fieldName' => 'website_type_id',
- ),
- 'address' => array('skip' => TRUE, 'customData' => 1),
- 'email' => array('skip' => TRUE),
- 'openid' => array('skip' => TRUE),
- );
+ ],
+ 'address' => ['skip' => TRUE, 'customData' => 1],
+ 'email' => ['skip' => TRUE],
+ 'openid' => ['skip' => TRUE],
+ ];
foreach ($communicationType as $key => $value) {
if (!empty($defaults[$key])) {
foreach ($defaults[$key] as & $val) {
- CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE);
+ CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', ['labelColumn' => 'display_name']), FALSE);
if (empty($value['skip'])) {
$daoName = $value['daoName'];
$pseudoConst = $daoName::buildOptions($value['fieldName'], 'get');
}
}
- if (!empty($defaults['gender_id'])) {
- $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']);
- }
+ $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id'] ?? NULL);
$communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id');
if (!empty($communicationStyle)) {
$defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', ');
// get contact tags
- $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
-
- if (!empty($contactTags)) {
- $defaults['contactTag'] = $contactTags;
+ $defaults['contactTag'] = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);
+ if (!empty($defaults['contactTag'])) {
$defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE);
}
if (!empty($addressValue['master_id']) &&
!$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
) {
- $sharedAddresses[$key]['shared_address_display'] = array(
+ $sharedAddresses[$key]['shared_address_display'] = [
'address' => $addressValue['display'],
'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
- );
+ ];
}
}
$this->assign('sharedAddresses', $sharedAddresses);
- //get the current employer name
- if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') {
- if ($contact->employer_id && $contact->organization_name) {
- $defaults['current_employer'] = $contact->organization_name;
- $defaults['current_employer_id'] = $contact->employer_id;
- }
- }
-
- $defaults['external_identifier'] = $contact->external_identifier;
$this->assign($defaults);
// FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query
$context = ['contact_id' => $this->_contactId];
CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
- // Get tab counts last to avoid wasting time; if a tab was removed by hook, the count isn't needed.
+ $expectedKeys = ['count', 'class', 'template', 'hideCount', 'icon'];
+
foreach ($allTabs as &$tab) {
+ // Ensure tab has all expected keys
+ $tab += array_fill_keys($expectedKeys, NULL);
+ // Get tab counts last to avoid wasting time; if a tab was removed by hook, the count isn't needed.
if (!isset($tab['count']) && isset($getCountParams[$tab['id']])) {
- $tab['count'] = call_user_func_array(['CRM_Contact_BAO_Contact', 'getCountComponent'], $getCountParams[$tab['id']]);
+ $tab['count'] = call_user_func_array([
+ 'CRM_Contact_BAO_Contact',
+ 'getCountComponent',
+ ], $getCountParams[$tab['id']]);
}
}
// now sort the tabs based on weight
usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']);
- $expectedKeys = ['count', 'class', 'template', 'hideCount', 'icon'];
- foreach ($allTabs as $index => $tab) {
- foreach ($expectedKeys as $key) {
- if (!array_key_exists($key, $tab)) {
- $allTabs[$index][$key] = NULL;
- }
- }
- }
return $allTabs;
}