updated example & a couple of tidy ups to throw API_Exception rather than legacy
[civicrm-core.git] / api / v3 / examples / Contact / GetFieldsOptions.php
index fac0bae4e7eb9524e2ad6c61d0cec7a176e345d7..4337b348705ad811d8a7574d3a8484f919f3f3ff 100644 (file)
@@ -1,23 +1,31 @@
 <?php
-
-/*
- Demonstrate retrieving metadata with custom field options
+/**
+ * Test Generated example of using contact GetFields API
+ * Demonstrate retrieving metadata with custom field options *
  */
 function contact_getfields_example(){
 $params = array(
   'options' => array(
       'get_options' => 'custom_1',
     ),
-  'version' => 3,
   'action' => 'create',
 );
 
-  $result = civicrm_api( 'contact','GetFields',$params );
+try{
+  $result = civicrm_api3('contact', 'GetFields', $params);
+}
+catch (CiviCRM_API3_Exception $e) {
+  // handle error here
+  $errorMessage = $e->getMessage();
+  $errorCode = $e->getErrorCode();
+  $errorData = $e->getExtraParams();
+  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
+}
 
-  return $result;
+return $result;
 }
 
-/*
+/**
  * Function returns array of result expected from previous function
  */
 function contact_getfields_expectedresult(){
@@ -312,6 +320,10 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'individual_prefix',
             ),
+          'api.aliases' => array(
+              '0' => 'individual_prefix',
+              '1' => 'individual_prefix_id',
+            ),
         ),
       'suffix_id' => array(
           'name' => 'suffix_id',
@@ -325,6 +337,10 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'individual_suffix',
             ),
+          'api.aliases' => array(
+              '0' => 'individual_suffix',
+              '1' => 'individual_suffix_id',
+            ),
         ),
       'email_greeting_id' => array(
           'name' => 'email_greeting_id',
@@ -544,6 +560,7 @@ function contact_getfields_expectedresult(){
           'groupTitle' => 'select_test_g',
           'data_type' => 'String',
           'html_type' => 'Select',
+          'default_value' => '',
           'text_length' => '',
           'options_per_line' => '',
           'custom_group_id' => '1',
@@ -553,10 +570,11 @@ function contact_getfields_expectedresult(){
           'extends_entity_column_id' => '',
           'is_view' => 0,
           'is_multiple' => 0,
-          'option_group_id' => '97',
+          'option_group_id' => '99',
           'date_format' => '',
           'time_format' => '',
           'name' => 'custom_1',
+          'type' => 2,
           'options' => array(
               '1' => 'Label1',
               '2' => 'Label2',
@@ -565,6 +583,7 @@ function contact_getfields_expectedresult(){
       'current_employer' => array(
           'title' => 'Current Employer',
           'description' => 'Name of Current Employer',
+          'type' => 2,
         ),
       'dupe_check' => array(
           'title' => 'Check for Duplicates',
@@ -573,7 +592,7 @@ function contact_getfields_expectedresult(){
     ),
 );
 
-  return $expectedResult  ;
+  return $expectedResult;
 }