Merge pull request #5046 from totten/master-resolver
[civicrm-core.git] / api / v3 / examples / UFField / Create.php
1 <?php
2 /**
3 * Test Generated example of using uf_field create API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function uf_field_create_example() {
10 $params = array(
11 'field_name' => 'phone',
12 'field_type' => 'Contact',
13 'visibility' => 'Public Pages and Listings',
14 'weight' => 1,
15 'label' => 'Test Phone',
16 'is_searchable' => 1,
17 'is_active' => 1,
18 'location_type_id' => 1,
19 'phone_type_id' => 1,
20 'uf_group_id' => 11,
21 );
22
23 try{
24 $result = civicrm_api3('uf_field', 'create', $params);
25 }
26 catch (CiviCRM_API3_Exception $e) {
27 // Handle error here.
28 $errorMessage = $e->getMessage();
29 $errorCode = $e->getErrorCode();
30 $errorData = $e->getExtraParams();
31 return array(
32 'error' => $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 = array(
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 1,
54 'values' => array(
55 '1' => array(
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
85 * testCreateUFField
86 * and can be found in
87 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php
88 *
89 * You can see the outcome of the API tests at
90 * https://test.civicrm.org/job/CiviCRM-master-git/
91 *
92 * To Learn about the API read
93 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
94 *
95 * Browse the api on your own site with the api explorer
96 * http://MYSITE.ORG/path/to/civicrm/api
97 *
98 * Read more about testing here
99 * http://wiki.civicrm.org/confluence/display/CRM/Testing
100 *
101 * API Standards documentation:
102 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
103 */