Merge pull request #9769 from scardinius/crm-19958
[civicrm-core.git] / api / v3 / examples / UFField / Create.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the UFField.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function uf_field_create_example() {
9 $params = array(
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 );
6a488035 21
50fb255d 22 try{
a828d7b8 23 $result = civicrm_api3('UFField', 'create', $params);
50fb255d 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(
1d8ee3d6 31 'is_error' => 1,
32 'error_message' => $errorMessage,
50fb255d 33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 );
36 }
37
38 return $result;
6a488035
TO
39}
40
fb32de45 41/**
50fb255d 42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
6a488035 46 */
50fb255d 47function uf_field_create_expectedresult() {
6a488035 48
ee600d6f 49 $expectedResult = array(
50fb255d 50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 1,
54 'values' => array(
ee600d6f 55 '1' => array(
50fb255d 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 ),
6a488035 76 ),
50fb255d 77 );
6a488035 78
fb32de45 79 return $expectedResult;
6a488035
TO
80}
81
a828d7b8 82/*
50fb255d 83* This example has been generated from the API test suite.
a828d7b8
CW
84* The test that created it is called "testCreateUFField"
85* and can be found at:
69d79249 86* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php
6a488035
TO
87*
88* You can see the outcome of the API tests at
69d79249 89* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
90*
91* To Learn about the API read
69d79249 92* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 93*
69d79249 94* Browse the api on your own site with the api explorer
41d4d31f 95* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
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
b259a4ab 102*/