Merge pull request #2749 from monishdeb/HR-317
[civicrm-core.git] / api / v3 / examples / CustomField / Create.php
1 <?php
2 /**
3 * Test Generated example of using custom_field create API
4 * *
5 */
6 function custom_field_create_example(){
7 $params = array(
8 'custom_group_id' => 1,
9 'name' => 'test_textfield2',
10 'label' => 'Name1',
11 'html_type' => 'Text',
12 'data_type' => 'String',
13 'default_value' => 'abc',
14 'weight' => 4,
15 'is_required' => 1,
16 'is_searchable' => 0,
17 'is_active' => 1,
18 );
19
20 try{
21 $result = civicrm_api3('custom_field', 'create', $params);
22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // handle error here
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
29 }
30
31 return $result;
32 }
33
34 /**
35 * Function returns array of result expected from previous function
36 */
37 function custom_field_create_expectedresult(){
38
39 $expectedResult = array(
40 'is_error' => 0,
41 'version' => 3,
42 'count' => 1,
43 'id' => 1,
44 'values' => array(
45 '1' => array(
46 'id' => '1',
47 'custom_group_id' => '1',
48 'name' => 'test_textfield2',
49 'label' => 'Name1',
50 'data_type' => 'String',
51 'html_type' => 'Text',
52 'default_value' => 'abc',
53 'is_required' => '1',
54 'is_searchable' => 0,
55 'is_search_range' => 0,
56 'weight' => '4',
57 'help_pre' => '',
58 'help_post' => '',
59 'mask' => '',
60 'attributes' => '',
61 'javascript' => '',
62 'is_active' => '1',
63 'is_view' => 0,
64 'options_per_line' => '',
65 'text_length' => '',
66 'start_date_years' => '',
67 'end_date_years' => '',
68 'date_format' => '',
69 'time_format' => '',
70 'note_columns' => '',
71 'note_rows' => '',
72 'column_name' => 'name1_1',
73 'option_group_id' => '',
74 'filter' => '',
75 ),
76 ),
77 );
78
79 return $expectedResult;
80 }
81
82
83 /*
84 * This example has been generated from the API test suite. The test that created it is called
85 *
86 * testCustomFieldCreateWithEdit and can be found in
87 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CustomFieldTest.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/explorer
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 */