CRM-14181, remove special handing for enums
[civicrm-core.git] / api / v3 / Generic.php
index 392fd4cf722872bd583d9e1d093dde147f3260e4..fd4d934c54314d4de65f139543300e0536054c71 100644 (file)
@@ -187,7 +187,7 @@ function civicrm_api3_generic_getvalue($apiRequest) {
   }
 
   // we only take "return=" as valid options
-  if (CRM_Utils_Array::value('return', $apiRequest['params'])) {
+  if (!empty($apiRequest['params']['return'])) {
     if (!isset($result['values'][0][$apiRequest['params']['return']])) {
       return civicrm_api3_create_error("field " . $apiRequest['params']['return'] . " unset or not existing", array('invalid_field' => $apiRequest['params']['return']));
     }
@@ -228,11 +228,18 @@ function civicrm_api3_generic_getoptions($apiRequest) {
   unset($apiRequest['params']['context'], $apiRequest['params']['field']);
 
   $baoName = _civicrm_api3_get_BAO($apiRequest['entity']);
-  $options = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
+  $options = $output = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
   if ($options === FALSE) {
     return civicrm_api3_create_error("The field '{$fieldName}' has no associated option list.");
   }
-  return civicrm_api3_create_success($options);
+  // Support 'sequential' output as a non-associative array
+  if (!empty($apiRequest['params']['sequential'])) {
+    $output = array();
+    foreach ($options as $key => $val) {
+      $output[] = array('key' => $key, 'value' => $val);
+    }
+  }
+  return civicrm_api3_create_success($output);
 }
 
 /**
@@ -243,7 +250,6 @@ function civicrm_api3_generic_getoptions($apiRequest) {
  * - the reason for this is that checking / transformation is done on pseudoconstants but
  * - if the field is an FK then mysql will enforce the data quality (& we have handling on failure)
  * @todo - if may be we should define a 'resolve' key on the psuedoconstant for when these rules are not fine enough
- * 3) if there is an 'enum' then it is split up into the relevant options
  *
  * This function is only split out for the purpose of code clarity / comment block documentation
  * @param array $metadata the array of metadata that will form the result of the getfields function
@@ -252,7 +258,7 @@ function civicrm_api3_generic_getoptions($apiRequest) {
  * @param array $fieldsToResolve anny field resolutions specifically requested
  */
 function _civicrm_api3_generic_get_metadata_options(&$metadata, $entity, $fieldname, $fieldSpec, $fieldsToResolve){
-  if(empty($fieldSpec['pseudoconstant']) && empty($fieldSpec['enumValues'])) {
+  if (empty($fieldSpec['pseudoconstant'])) {
     return;
   }