3 * Test Generated example demonstrating the Profile.getfields API.
5 * demonstrates retrieving profile fields passing in an id
10 function profile_getfields_example() {
17 $result = civicrm_api3('Profile', 'getfields', $params);
19 catch (CiviCRM_API3_Exception
$e) {
21 $errorMessage = $e->getMessage();
22 $errorCode = $e->getErrorCode();
23 $errorData = $e->getExtraParams();
26 'error_message' => $errorMessage,
27 'error_code' => $errorCode,
28 'error_data' => $errorData,
36 * Function returns array of result expected from previous function.
41 function profile_getfields_expectedresult() {
50 'label' => '_addCustomFieldToProfile',
51 'headerPattern' => '//',
52 'title' => 'first_name',
53 'custom_field_id' => '1',
54 'groupTitle' => '_addCustomFieldToProfile',
55 'data_type' => 'String',
58 'html_type' => 'Text',
59 'default_value' => 'defaultValue',
61 'options_per_line' => '',
62 'custom_group_id' => '1',
63 'extends' => 'Contact',
64 'is_search_range' => 0,
65 'extends_entity_column_value' => '',
66 'extends_entity_column_id' => '',
69 'option_group_id' => '',
73 'table_name' => 'civicrm_value__addcustomfie_1',
74 'column_name' => '_addcustomfieldtoprofile_1',
75 'where' => 'civicrm_value__addcustomfie_1._addcustomfieldtoprofile_1',
76 'extends_table' => 'civicrm_contact',
77 'search_table' => 'contact_a',
78 'api.required' => '1',
81 'entity' => 'contact',
86 'name' => 'postal_code',
88 'title' => 'State Province',
89 'description' => 'Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.',
93 'where' => 'civicrm_address.postal_code',
94 'headerPattern' => '/postal|zip/i',
95 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/',
97 'table_name' => 'civicrm_address',
98 'entity' => 'address',
99 'bao' => 'CRM_Core_BAO_Address',
106 'is_core_field' => TRUE,
113 'state_province-1' => [
114 'name' => 'state_province_id',
116 'title' => 'State Province',
117 'description' => 'Which State_Province does this address belong to.',
118 'where' => 'civicrm_address.state_province_id',
119 'table_name' => 'civicrm_address',
120 'entity' => 'address',
121 'bao' => 'CRM_Core_BAO_Address',
123 'localize_context' => 'province',
124 'FKClassName' => 'CRM_Core_DAO_StateProvince',
126 'type' => 'ChainSelect',
130 'pseudoconstant' => [
131 'table' => 'civicrm_state_province',
133 'labelColumn' => 'name',
135 'is_core_field' => TRUE,
136 'FKApiName' => 'StateProvince',
137 'api.required' => '1',
144 'name' => 'country_id',
146 'title' => 'Country',
147 'description' => 'Which Country does this address belong to.',
148 'where' => 'civicrm_address.country_id',
149 'table_name' => 'civicrm_address',
150 'entity' => 'address',
151 'bao' => 'CRM_Core_BAO_Address',
153 'localize_context' => 'country',
154 'FKClassName' => 'CRM_Core_DAO_Country',
160 'pseudoconstant' => [
161 'table' => 'civicrm_country',
163 'labelColumn' => 'name',
164 'nameColumn' => 'iso_code',
165 'abbrColumn' => 'iso_code',
167 'is_core_field' => TRUE,
168 'FKApiName' => 'Country',
169 'api.required' => '1',
179 'description' => 'Complete phone number.',
183 'where' => 'civicrm_phone.phone',
184 'headerPattern' => '/phone/i',
185 'dataPattern' => '/^[\\d\\(\\)\\-\\.\\s]+$/',
187 'table_name' => 'civicrm_phone',
189 'bao' => 'CRM_Core_BAO_Phone',
196 'is_core_field' => TRUE,
197 'api.required' => '1',
207 'description' => 'Email address',
211 'where' => 'civicrm_email.email',
212 'headerPattern' => '/e.?mail/i',
213 'dataPattern' => '/^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$/',
216 'table_name' => 'civicrm_email',
218 'bao' => 'CRM_Core_BAO_Email',
225 'is_core_field' => TRUE,
226 'api.required' => '1',
231 '0' => 'email-Primary',
235 'name' => 'last_name',
237 'title' => 'Last Name',
238 'description' => 'Last Name.',
242 'where' => 'civicrm_contact.last_name',
243 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
244 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
246 'table_name' => 'civicrm_contact',
247 'entity' => 'contact',
248 'bao' => 'CRM_Contact_BAO_Contact',
255 'is_core_field' => TRUE,
256 'api.required' => '1',
263 'name' => 'first_name',
265 'title' => 'First Name',
266 'description' => 'First Name.',
270 'where' => 'civicrm_contact.first_name',
271 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
272 'dataPattern' => '/^\\w+$/',
274 'table_name' => 'civicrm_contact',
275 'entity' => 'contact',
276 'bao' => 'CRM_Contact_BAO_Contact',
283 'is_core_field' => TRUE,
284 'api.required' => '1',
291 'api.required' => TRUE,
292 'title' => 'Profile ID',
293 'name' => 'profile_id',
298 return $expectedResult;
302 * This example has been generated from the API test suite.
303 * The test that created it is called "testGetFields"
304 * and can be found at:
305 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
307 * You can see the outcome of the API tests at
308 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
310 * To Learn about the API read
311 * https://docs.civicrm.org/dev/en/latest/api/
313 * Browse the API on your own site with the API Explorer. It is in the main
314 * CiviCRM menu, under: Support > Development > API Explorer.
316 * Read more about testing here
317 * https://docs.civicrm.org/dev/en/latest/testing/
319 * API Standards documentation:
320 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/