From: Seamus Lee Date: Sun, 26 Jul 2020 20:56:58 +0000 (+1000) Subject: Merge pull request #17941 from eileenmcnaughton/fieldspec X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=155a0c1b7bed3fb887e334d2efeb4494c145c6c4;hp=329618349ffa338a1006ef859f76b546babf96cf;p=civicrm-core.git Merge pull request #17941 from eileenmcnaughton/fieldspec [Ref] Simplify field reference --- diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 1338adaea1..58aa78ba16 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; } }