7dfa389705d5ad7a159e0fe078d82777f60ff7a8
[civicrm-core.git] / api / v3 / examples / UFField / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the UFField.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function uf_field_create_example() {
9 $params = [
10 'field_name' => 'phone',
11 'field_type' => 'Contact',
12 'visibility' => 'Public Pages and Listings',
13 'weight' => 1,
14 'label' => 'Test Phone',
15 'is_searchable' => 1,
16 'is_active' => 1,
17 'location_type_id' => 1,
18 'phone_type_id' => 1,
19 'uf_group_id' => 11,
20 ];
21
22 try{
23 $result = civicrm_api3('UFField', 'create', $params);
24 }
25 catch (CiviCRM_API3_Exception $e) {
26 // Handle error here.
27 $errorMessage = $e->getMessage();
28 $errorCode = $e->getErrorCode();
29 $errorData = $e->getExtraParams();
30 return [
31 'is_error' => 1,
32 'error_message' => $errorMessage,
33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 ];
36 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function uf_field_create_expectedresult() {
48
49 $expectedResult = [
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 1,
54 'values' => [
55 '1' => [
56 'id' => '1',
57 'uf_group_id' => '11',
58 'field_name' => 'phone',
59 'is_active' => '1',
60 'is_view' => '',
61 'is_required' => '',
62 'weight' => '1',
63 'help_post' => '',
64 'help_pre' => '',
65 'visibility' => 'Public Pages and Listings',
66 'in_selector' => '',
67 'is_searchable' => '1',
68 'location_type_id' => '1',
69 'phone_type_id' => '1',
70 'website_type_id' => '',
71 'label' => 'Test Phone',
72 'field_type' => 'Contact',
73 'is_reserved' => '',
74 'is_multi_summary' => '',
75 ],
76 ],
77 ];
78
79 return $expectedResult;
80 }
81
82 /*
83 * This example has been generated from the API test suite.
84 * The test that created it is called "testCreateUFField"
85 * and can be found at:
86 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php
87 *
88 * You can see the outcome of the API tests at
89 * https://test.civicrm.org/job/CiviCRM-master-git/
90 *
91 * To Learn about the API read
92 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
93 *
94 * Browse the api on your own site with the api explorer
95 * http://MYSITE.ORG/path/to/civicrm/api
96 *
97 * Read more about testing here
98 * http://wiki.civicrm.org/confluence/display/CRM/Testing
99 *
100 * API Standards documentation:
101 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
102 */