Support "unique names" as well as sql name CRM-12464
authorColeman Watts <coleman@civicrm.org>
Tue, 16 Jul 2013 00:51:21 +0000 (17:51 -0700)
committerColeman Watts <coleman@civicrm.org>
Tue, 16 Jul 2013 00:51:21 +0000 (17:51 -0700)
----------------------------------------
* CRM-12464: Add PseudoConstants to Schema Metadata
  http://issues.civicrm.org/jira/browse/CRM-12464

CRM/Core/PseudoConstant.php

index 82faf63e33f6578c44dc8c0e7929a64b21bbb686..2cabc11fb212ab2360931ad0808e07e790262889 100644 (file)
@@ -260,8 +260,14 @@ class CRM_Core_PseudoConstant {
     $dao = new $daoName;
     $fields = $dao->fields();
     $fieldKeys = $dao->fieldKeys();
-    $fieldKey = $fieldKeys[$fieldName];
     $dao->free();
+
+    // Support "unique names" as well as sql names
+    $fieldKey = $fieldName;
+    if (empty($fields[$fieldKey])) {
+      $fieldKey = $fieldKeys[$fieldName];
+    }
+    // If neither worked then this field doesn't exist. Return false.
     if (empty($fields[$fieldKey])) {
       return FALSE;
     }
@@ -320,9 +326,7 @@ class CRM_Core_PseudoConstant {
             return FALSE;
           }
           // Get list of fields for the option table
-          $dao = new $daoName;
-          $availableFields = array_keys($dao->fieldKeys());
-          $dao->free();
+          $availableFields = array_keys($fieldKeys);
 
           $select = "SELECT %1 AS id, %2 AS label";
           $from = "FROM %3";