X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2Fexamples%2FUFField%2FCreate.php;h=ec39ee0013833f21a10c5ba5d5be1f6cec1efdd0;hb=a828d7b823956a46f5a3cea184389c9b108f80ac;hp=8382d9f5333c0fa8098917443882ab51e1470b26;hpb=6aa0c369233f7935ac4969b3feeec097086871bf;p=civicrm-core.git diff --git a/api/v3/examples/UFField/Create.php b/api/v3/examples/UFField/Create.php index 8382d9f533..ec39ee0013 100644 --- a/api/v3/examples/UFField/Create.php +++ b/api/v3/examples/UFField/Create.php @@ -1,78 +1,87 @@ 'phone', - 'field_type' => 'Contact', - 'visibility' => 'Public Pages and Listings', - 'weight' => 1, - 'label' => 'Test Phone', - 'is_searchable' => 1, - 'is_active' => 1, - 'location_type_id' => 1, - 'phone_type_id' => 1, - 'uf_group_id' => 11, -); +function uf_field_create_example() { + $params = array( + 'field_name' => 'phone', + 'field_type' => 'Contact', + 'visibility' => 'Public Pages and Listings', + 'weight' => 1, + 'label' => 'Test Phone', + 'is_searchable' => 1, + 'is_active' => 1, + 'location_type_id' => 1, + 'phone_type_id' => 1, + 'uf_group_id' => 11, + ); -try{ - $result = civicrm_api3('uf_field', 'create', $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); -} + try{ + $result = civicrm_api3('UFField', 'create', $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 returns array of result expected from previous function. + * + * @return array + * API result array */ -function uf_field_create_expectedresult(){ +function uf_field_create_expectedresult() { $expectedResult = array( - 'is_error' => 0, - 'version' => 3, - 'count' => 1, - 'id' => 1, - 'values' => array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'id' => 1, + 'values' => array( '1' => array( - 'id' => '1', - 'uf_group_id' => '11', - 'field_name' => 'phone', - 'is_active' => '1', - 'is_view' => '', - 'is_required' => '', - 'weight' => '1', - 'help_post' => '', - 'help_pre' => '', - 'visibility' => 'Public Pages and Listings', - 'in_selector' => '', - 'is_searchable' => '1', - 'location_type_id' => '1', - 'phone_type_id' => '1', - 'label' => 'Test Phone', - 'field_type' => 'Contact', - 'is_reserved' => '', - 'is_multi_summary' => '', - ), + 'id' => '1', + 'uf_group_id' => '11', + 'field_name' => 'phone', + 'is_active' => '1', + 'is_view' => '', + 'is_required' => '', + 'weight' => '1', + 'help_post' => '', + 'help_pre' => '', + 'visibility' => 'Public Pages and Listings', + 'in_selector' => '', + 'is_searchable' => '1', + 'location_type_id' => '1', + 'phone_type_id' => '1', + 'website_type_id' => '', + 'label' => 'Test Phone', + 'field_type' => 'Contact', + 'is_reserved' => '', + 'is_multi_summary' => '', + ), ), -); + ); return $expectedResult; } - /* -* This example has been generated from the API test suite. The test that created it is called -* -* testCreateUFField and can be found in +* This example has been generated from the API test suite. +* The test that created it is called "testCreateUFField" +* and can be found at: * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php * * You can see the outcome of the API tests at @@ -82,7 +91,7 @@ function uf_field_create_expectedresult(){ * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API * * Browse the api on your own site with the api explorer -* http://MYSITE.ORG/path/to/civicrm/api/explorer +* http://MYSITE.ORG/path/to/civicrm/api * * Read more about testing here * http://wiki.civicrm.org/confluence/display/CRM/Testing