Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 2 | /** |
3 | * Test Generated example of using uf_field create API | |
4 | * * | |
6a488035 TO |
5 | */ |
6 | function uf_field_create_example(){ | |
ee600d6f | 7 | $params = array( |
6a488035 TO |
8 | 'field_name' => 'phone', |
9 | 'field_type' => 'Contact', | |
10 | 'visibility' => 'Public Pages and Listings', | |
11 | 'weight' => 1, | |
12 | 'label' => 'Test Phone', | |
13 | 'is_searchable' => 1, | |
14 | 'is_active' => 1, | |
15 | 'location_type_id' => 1, | |
16 | 'phone_type_id' => 1, | |
6a488035 TO |
17 | 'uf_group_id' => 11, |
18 | ); | |
19 | ||
fb32de45 | 20 | try{ |
21 | $result = civicrm_api3('uf_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 | } | |
6a488035 | 30 | |
fb32de45 | 31 | return $result; |
6a488035 TO |
32 | } |
33 | ||
fb32de45 | 34 | /** |
6a488035 TO |
35 | * Function returns array of result expected from previous function |
36 | */ | |
37 | function uf_field_create_expectedresult(){ | |
38 | ||
ee600d6f | 39 | $expectedResult = array( |
6a488035 TO |
40 | 'is_error' => 0, |
41 | 'version' => 3, | |
42 | 'count' => 1, | |
43 | 'id' => 1, | |
ee600d6f | 44 | 'values' => array( |
45 | '1' => array( | |
6a488035 TO |
46 | 'id' => '1', |
47 | 'uf_group_id' => '11', | |
48 | 'field_name' => 'phone', | |
49 | 'is_active' => '1', | |
50 | 'is_view' => '', | |
51 | 'is_required' => '', | |
52 | 'weight' => '1', | |
53 | 'help_post' => '', | |
54 | 'help_pre' => '', | |
55 | 'visibility' => 'Public Pages and Listings', | |
56 | 'in_selector' => '', | |
57 | 'is_searchable' => '1', | |
58 | 'location_type_id' => '1', | |
59 | 'phone_type_id' => '1', | |
60 | 'label' => 'Test Phone', | |
61 | 'field_type' => 'Contact', | |
62 | 'is_reserved' => '', | |
63 | 'is_multi_summary' => '', | |
64 | ), | |
65 | ), | |
66 | ); | |
67 | ||
fb32de45 | 68 | return $expectedResult; |
6a488035 TO |
69 | } |
70 | ||
71 | ||
72 | /* | |
73 | * This example has been generated from the API test suite. The test that created it is called | |
74 | * | |
75 | * testCreateUFField and can be found in | |
76 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/UFFieldTest.php | |
77 | * | |
78 | * You can see the outcome of the API tests at | |
79 | * http://tests.dev.civicrm.org/trunk/results-api_v3 | |
80 | * | |
81 | * To Learn about the API read | |
82 | * http://book.civicrm.org/developer/current/techniques/api/ | |
83 | * | |
84 | * and review the wiki at | |
85 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs | |
86 | * | |
87 | * Read more about testing here | |
88 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
89 | * | |
90 | * API Standards documentation: | |
91 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
92 | */ |