diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 305873f410d4..5122ec5079ae 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -134,7 +134,7 @@ public static function add(&$params) { unset($params['preferred_communication_method']); } - $defaults = ['source' => CRM_Utils_Array::value('contact_source', $params)]; + $defaults = ['source' => $params['contact_source'] ?? NULL]; if ($params['contact_type'] === 'Organization' && isset($params['organization_name'])) { $defaults['display_name'] = $params['organization_name']; $defaults['sort_name'] = $params['organization_name']; @@ -165,13 +165,10 @@ public static function add(&$params) { } $privacy = $params['privacy'] ?? NULL; - if ($privacy && - is_array($privacy) && - !empty($privacy) - ) { + if ($privacy && is_array($privacy)) { $allNull = FALSE; foreach (self::$_commPrefs as $name) { - $contact->$name = CRM_Utils_Array::value($name, $privacy, FALSE); + $contact->$name = $privacy[$name] ?? FALSE; } } @@ -199,19 +196,14 @@ public static function add(&$params) { if ($contact->contact_type === 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) { // Create current employer. - $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params); + $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : $params['current_employer'] ?? NULL; - $newContact = FALSE; - if (empty($params['contact_id'])) { - $newContact = TRUE; - } + $newContact = empty($params['contact_id']); if ($newEmployer) { CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact); } - else { - if ($employerId) { - CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId); - } + elseif ($employerId) { + CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId); } } @@ -444,7 +436,7 @@ public static function unsetProtectedFields(&$contacts) { $currentUser = CRM_Core_Session::getLoggedInContactID(); $editOwn = $currentUser && CRM_Core_Permission::check('edit own api keys'); foreach ($contacts as &$contact) { - $cid = is_object($contact) ? $contact->id : CRM_Utils_Array::value('id', $contact); + $cid = is_object($contact) ? $contact->id : $contact['id'] ?? NULL; if (!($editOwn && $cid == $currentUser)) { if (is_object($contact)) { unset($contact->api_key); @@ -827,7 +819,7 @@ public static function resolveDefaults(&$defaults, $reverse = FALSE) { $reverse ); } - $stateProvinceID = self::resolveStateProvinceID($values, CRM_Utils_Array::value('country_id', $values)); + $stateProvinceID = self::resolveStateProvinceID($values, $values['country_id'] ?? NULL); if ($stateProvinceID) { $values['state_province_id'] = $stateProvinceID; } @@ -1372,7 +1364,7 @@ public static function importableFields( $cacheKeyString .= $checkPermission ? '_1' : '_0'; $cacheKeyString .= '_' . CRM_Core_Config::domainID() . '_'; - $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields) ?: Civi::cache('fields')->get($cacheKeyString); + $fields = self::$_importableFields[$cacheKeyString] ?? Civi::cache('fields')->get($cacheKeyString); if (!$fields) { $fields = CRM_Contact_DAO_Contact::import(); @@ -1525,7 +1517,7 @@ public static function &exportableFields($contactType = 'Individual', $status = //as an interim fix we will cache the fields by contact $cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID(); - if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { + if (!self::$_exportableFields || empty(self::$_exportableFields[$cacheKeyString])) { if (!self::$_exportableFields) { self::$_exportableFields = []; } @@ -2003,8 +1995,8 @@ public static function createProfileContact( // manage is_opt_out if (array_key_exists('is_opt_out', $fields) && array_key_exists('is_opt_out', $params)) { - $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE); - $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE); + $wasOptOut = $contactDetails['is_opt_out'] ?? FALSE; + $isOptOut = $params['is_opt_out']; $data['is_opt_out'] = $isOptOut; // on change, create new civicrm_subscription_history entry if (($wasOptOut != $isOptOut) && !empty($contactDetails['contact_id'])) { @@ -3702,7 +3694,7 @@ public static function getEntityRefCreateLinks($appendProfiles = []) { 'url' => CRM_Utils_System::url('civicrm/profile/create', "reset=1&context=dialog&gid=$id", NULL, NULL, FALSE, FALSE, TRUE), 'type' => ucfirst(str_replace('new_', '', $profile['name'])), - 'icon' => CRM_Utils_Array::value(str_replace('new_', '', $profile['name']), $icons), + 'icon' => $icons[str_replace('new_', '', $profile['name'])] ?? NULL, ]; } else {