Merge pull request #1625 from pradpnayak/CRM-13340
[civicrm-core.git] / api / v3 / CustomField.php
index 300f0d72e672db08af9f6f8b0a0212d05672b1b8..6a41b74be23d1db2208a886d6d95a12fec7a5b21 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -74,12 +74,20 @@ function civicrm_api3_custom_field_create($params) {
       $params['option_weight'][$key] = $value['weight'];
     }
   }
+  $values = array();
   $customField = CRM_Core_BAO_CustomField::create($params);
-  civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1));
   _civicrm_api3_object_to_array_unique_fields($customField, $values[$customField->id]);
+  _civicrm_api3_custom_field_flush_static_caches();
   return civicrm_api3_create_success($values, $params, 'custom_field', $customField);
 }
 
+/**
+ * Flush static caches in functions that might have stored available custom fields
+ */
+function _civicrm_api3_custom_field_flush_static_caches(){
+  civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1));
+  CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE);
+}
 /**
  * Adjust Metadata for Create action
  *
@@ -92,7 +100,7 @@ function _civicrm_api3_custom_field_create_spec(&$params) {
   $params['option_type'] = array(
     'title' => 'This (boolean) field tells the BAO to create an option group for the field if the field type is appropriate',
     'api.default' => 1,
-    'type' => CRM_Utils_Type::T_BOOL,
+    'type' => CRM_Utils_Type::T_BOOLEAN,
   );
   $params['data_type']['api.default'] = 'String';
   $params['is_active']['api.default'] = 1;