f8e91c0bfada76cfe6c79a8718622de886b71f19
[civicrm-core.git] / api / v3 / examples / CustomField / Create.php
1 <?php
2 /**
3 * Test Generated example of using custom_field create API.
4 *
5 * @return array
6 * API result array
7 */
8 function custom_field_create_example() {
9 $params = array(
10 'custom_group_id' => 1,
11 'name' => 'test_textfield2',
12 'label' => 'Name1',
13 'html_type' => 'Text',
14 'data_type' => 'String',
15 'default_value' => 'abc',
16 'weight' => 4,
17 'is_required' => 1,
18 'is_searchable' => 0,
19 'is_active' => 1,
20 );
21
22 try{
23 $result = civicrm_api3('custom_field', '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 array(
31 'error' => $errorMessage,
32 'error_code' => $errorCode,
33 'error_data' => $errorData,
34 );
35 }
36
37 return $result;
38 }
39
40 /**
41 * Function returns array of result expected from previous function.
42 *
43 * @return array
44 * API result array
45 */
46 function custom_field_create_expectedresult() {
47
48 $expectedResult = array(
49 'is_error' => 0,
50 'version' => 3,
51 'count' => 1,
52 'id' => 1,
53 'values' => array(
54 '1' => array(
55 'id' => '1',
56 'custom_group_id' => '1',
57 'name' => 'test_textfield2',
58 'label' => 'Name1',
59 'data_type' => 'String',
60 'html_type' => 'Text',
61 'default_value' => 'abc',
62 'is_required' => '1',
63 'is_searchable' => 0,
64 'is_search_range' => 0,
65 'weight' => '4',
66 'help_pre' => '',
67 'help_post' => '',
68 'mask' => '',
69 'attributes' => '',
70 'javascript' => '',
71 'is_active' => '1',
72 'is_view' => 0,
73 'options_per_line' => '',
74 'text_length' => '',
75 'start_date_years' => '',
76 'end_date_years' => '',
77 'date_format' => '',
78 'time_format' => '',
79 'note_columns' => '',
80 'note_rows' => '',
81 'column_name' => 'name1_1',
82 'option_group_id' => '',
83 'filter' => '',
84 'in_selector' => 0,
85 ),
86 ),
87 );
88
89 return $expectedResult;
90 }
91
92 /**
93 * This example has been generated from the API test suite.
94 * The test that created it is called
95 * testCustomFieldCreateWithEdit
96 * and can be found in
97 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CustomFieldTest.php
98 *
99 * You can see the outcome of the API tests at
100 * https://test.civicrm.org/job/CiviCRM-master-git/
101 *
102 * To Learn about the API read
103 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
104 *
105 * Browse the api on your own site with the api explorer
106 * http://MYSITE.ORG/path/to/civicrm/api
107 *
108 * Read more about testing here
109 * http://wiki.civicrm.org/confluence/display/CRM/Testing
110 *
111 * API Standards documentation:
112 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
113 */