From: eileen Date: Fri, 24 Jul 2020 07:35:01 +0000 (+1200) Subject: [Ref] Simplify field reference X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=62b6031b4bd092420813882f96f2d03d2b45bcde;p=civicrm-core.git [Ref] Simplify field reference --- diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index a450729046..ca2d86dc52 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -1146,32 +1146,31 @@ class CRM_Export_BAO_ExportProcessor { return $i18n->crm_translate($fieldValue); default: - if (isset($metadata[$field])) { - // No I don't know why we do it this way & whether we could - // make better use of pseudoConstants. - if (!empty($metadata[$field]['context'])) { - return $i18n->crm_translate($fieldValue, $metadata[$field]); + $fieldSpec = $metadata[$field] ?? []; + // No I don't know why we do it this way & whether we could + // make better use of pseudoConstants. + if (!empty($fieldSpec['context'])) { + return $i18n->crm_translate($fieldValue, $fieldSpec); + } + if (!empty($fieldSpec['pseudoconstant'])) { + if (!empty($fieldSpec['bao'])) { + return CRM_Core_PseudoConstant::getLabel($fieldSpec['bao'], $fieldSpec['name'], $fieldValue); } - if (!empty($metadata[$field]['pseudoconstant'])) { - if (!empty($metadata[$field]['bao'])) { - return CRM_Core_PseudoConstant::getLabel($metadata[$field]['bao'], $metadata[$field]['name'], $fieldValue); - } - // This is not our normal syntax for pseudoconstants but I am a bit loath to - // call an external function until sure it is not increasing php processing given this - // may be iterated 100,000 times & we already have the $imProvider var loaded. - // That can be next refactor... - // Yes - definitely feeling hatred for this bit of code - I know you will beat me up over it's awfulness - // but I have to reach a stable point.... - $varName = $metadata[$field]['pseudoconstant']['var']; - if ($varName === 'imProviders') { - return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $fieldValue); - } - if ($varName === 'phoneTypes') { - return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Phone', 'phone_type_id', $fieldValue); - } + // This is not our normal syntax for pseudoconstants but I am a bit loath to + // call an external function until sure it is not increasing php processing given this + // may be iterated 100,000 times & we already have the $imProvider var loaded. + // That can be next refactor... + // Yes - definitely feeling hatred for this bit of code - I know you will beat me up over it's awfulness + // but I have to reach a stable point.... + $varName = $fieldSpec['pseudoconstant']['var']; + if ($varName === 'imProviders') { + return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $fieldValue); + } + if ($varName === 'phoneTypes') { + return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Phone', 'phone_type_id', $fieldValue); } - } + return $fieldValue; } }