Merge pull request #15168 from MegaphoneJon/class-fixes
[civicrm-core.git] / api / v3 / examples / Contact / CustomFieldGet.ex.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contact.get API.
50fb255d 4 *
5c49fee0 5 * This demonstrates setting a custom field through the API.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
10function contact_get_example() {
cf8f0fff 11 $params = [
50fb255d 12 'return.custom_1' => 1,
1d8ee3d6 13 'id' => 3,
cf8f0fff 14 ];
6a488035 15
50fb255d 16 try{
a828d7b8 17 $result = civicrm_api3('Contact', 'get', $params);
50fb255d 18 }
19 catch (CiviCRM_API3_Exception $e) {
20 // Handle error here.
21 $errorMessage = $e->getMessage();
22 $errorCode = $e->getErrorCode();
23 $errorData = $e->getExtraParams();
cf8f0fff 24 return [
5be22f39 25 'is_error' => 1,
26 'error_message' => $errorMessage,
50fb255d 27 'error_code' => $errorCode,
28 'error_data' => $errorData,
cf8f0fff 29 ];
50fb255d 30 }
31
32 return $result;
6a488035
TO
33}
34
fb32de45 35/**
50fb255d 36 * Function returns array of result expected from previous function.
37 *
38 * @return array
39 * API result array
6a488035 40 */
50fb255d 41function contact_get_expectedresult() {
6a488035 42
cf8f0fff 43 $expectedResult = [
50fb255d 44 'is_error' => 0,
45 'version' => 3,
46 'count' => 1,
1d8ee3d6 47 'id' => 3,
cf8f0fff
CW
48 'values' => [
49 '3' => [
1d8ee3d6 50 'contact_id' => '3',
50fb255d 51 'civicrm_value_testgetwithcu_1_id' => '1',
52 'custom_1' => 'custom string',
1d8ee3d6 53 'id' => '3',
cf8f0fff
CW
54 ],
55 ],
56 ];
6a488035 57
fb32de45 58 return $expectedResult;
6a488035
TO
59}
60
a828d7b8 61/*
50fb255d 62* This example has been generated from the API test suite.
a828d7b8
CW
63* The test that created it is called "testGetWithCustom"
64* and can be found at:
69d79249 65* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
66*
67* You can see the outcome of the API tests at
8390b11b 68* https://test.civicrm.org/job/CiviCRM-Core-Matrix/
6a488035
TO
69*
70* To Learn about the API read
8390b11b 71* https://docs.civicrm.org/dev/en/latest/api/
6a488035 72*
8390b11b
SL
73* Browse the API on your own site with the API Explorer. It is in the main
74* CiviCRM menu, under: Support > Development > API Explorer.
6a488035
TO
75*
76* Read more about testing here
8390b11b 77* https://docs.civicrm.org/dev/en/latest/testing/
6a488035
TO
78*
79* API Standards documentation:
8390b11b 80* https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
b259a4ab 81*/