Merge pull request #1168 from eileenmcnaughton/CRM-13059
[civicrm-core.git] / api / v3 / examples / Contact / GetFieldsOptions.php
index 425ebed3abf8bbffcc591d7d0426a79787675881..5605b345f34d31124e32d6a54346fdf0b042be6b 100644 (file)
@@ -1,23 +1,31 @@
 <?php
-
-/*
- Demonstrate retrieving 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(){
@@ -247,11 +255,6 @@ function contact_getfields_expectedresult(){
           'export' => true,
           'default' => 'Both',
           'enumValues' => 'Text, HTML, Both',
-          'options' => array(
-              '0' => 'Text',
-              '1' => 'HTML',
-              '2' => 'Both',
-            ),
         ),
       'hash' => array(
           'name' => 'hash',
@@ -317,9 +320,6 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'individual_prefix',
             ),
-          'api.aliases' => array(
-              '0' => 'prefix',
-            ),
         ),
       'suffix_id' => array(
           'name' => 'suffix_id',
@@ -333,9 +333,6 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'individual_suffix',
             ),
-          'api.aliases' => array(
-              '0' => 'suffix',
-            ),
         ),
       'email_greeting_id' => array(
           'name' => 'email_greeting_id',
@@ -423,9 +420,6 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'gender',
             ),
-          'api.aliases' => array(
-              '0' => 'gender',
-            ),
         ),
       'birth_date' => array(
           'name' => 'birth_date',
@@ -567,9 +561,10 @@ 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',
           'options' => array(
               '1' => 'Label1',
               '2' => 'Label2',
@@ -586,7 +581,7 @@ function contact_getfields_expectedresult(){
     ),
 );
 
-  return $expectedResult  ;
+  return $expectedResult;
 }