Merge pull request #17941 from eileenmcnaughton/fieldspec
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 26 Jul 2020 20:56:58 +0000 (06:56 +1000)
committerGitHub <noreply@github.com>
Sun, 26 Jul 2020 20:56:58 +0000 (06:56 +1000)
[Ref] Simplify field reference

CRM/Export/BAO/ExportProcessor.php

index 1338adaea14d4bd93aeb1052f273e16327076689..58aa78ba168a6bfe98bb09182a356613ee2a37a2 100644 (file)
@@ -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;
         }
       }