From 3dbc9ffe1bfaa66d3b40468e41e1b0f19db263df Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 26 Oct 2022 09:58:37 +1300 Subject: [PATCH] Minor code cleanup - use function to replace a few lines --- CRM/Contact/Form/Task/Label.php | 16 +++------------- CRM/Contact/Form/Task/LabelCommon.php | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/CRM/Contact/Form/Task/Label.php b/CRM/Contact/Form/Task/Label.php index e615a7a845..83d802ce49 100644 --- a/CRM/Contact/Form/Task/Label.php +++ b/CRM/Contact/Form/Task/Label.php @@ -97,18 +97,8 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task { public function postProcess($params = NULL) { $fv = $params ?: $this->controller->exportValues($this->_name); $locName = NULL; - //get the address format sequence from the config file - $mailingFormat = Civi::settings()->get('mailing_format'); - - $sequence = CRM_Utils_Address::sequence($mailingFormat); - foreach ($sequence as $v) { - $address[$v] = 1; - } - - if (array_key_exists('postal_code', $address)) { - $address['postal_code_suffix'] = 1; - } + $addressReturnProperties = CRM_Contact_Form_Task_LabelCommon::getAddressReturnProperties(); //build the returnproperties $returnProperties = ['display_name' => 1, 'contact_type' => 1, 'prefix_id' => 1]; @@ -158,13 +148,13 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task { if (!empty($fv['location_type_id'])) { $locType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $locName = $locType[$fv['location_type_id']]; - $location = ['location' => ["{$locName}" => $address]]; + $location = ['location' => ["{$locName}" => $addressReturnProperties]]; $returnProperties = array_merge($returnProperties, $location); $params[] = ['location_type', '=', [1 => $fv['location_type_id']], 0, 0]; $primaryLocationOnly = FALSE; } else { - $returnProperties = array_merge($returnProperties, $address); + $returnProperties = array_merge($returnProperties, $addressReturnProperties); $primaryLocationOnly = TRUE; } diff --git a/CRM/Contact/Form/Task/LabelCommon.php b/CRM/Contact/Form/Task/LabelCommon.php index 8a78005415..f8f01063ff 100644 --- a/CRM/Contact/Form/Task/LabelCommon.php +++ b/CRM/Contact/Form/Task/LabelCommon.php @@ -234,7 +234,7 @@ class CRM_Contact_Form_Task_LabelCommon { * return properties for address e.g * [street_address => 1, supplemental_address_1 => 1, supplemental_address_2 => 1] */ - public static function getAddressReturnProperties() { + public static function getAddressReturnProperties(): array { $mailingFormat = Civi::settings()->get('mailing_format'); $addressFields = CRM_Utils_Address::sequence($mailingFormat); -- 2.25.1