Commit | Line | Data |
---|---|---|
6a488035 | 1 | {literal}<?php{/literal} |
0c13f046 | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the {$entity}.{$action} API. |
0c13f046 | 4 | * |
a6ec24c4 CW |
5 | {if !empty($result.deprecated) && is_string($result.deprecated)} |
6 | * @deprecated | |
7 | * {$result.deprecated} | |
8 | {if !$description} | |
9 | * | |
10 | {/if} | |
11 | {/if} | |
0c13f046 | 12 | {if $description} |
5c49fee0 CW |
13 | {foreach from=$description item='line'} |
14 | * {$line} | |
15 | {/foreach} | |
947a37b4 | 16 | * |
7aaa05d2 | 17 | {/if} |
0c13f046 EM |
18 | * @return array |
19 | * API result array | |
6a488035 | 20 | */ |
0c13f046 EM |
21 | function {$function}_example() {literal}{{/literal} |
22 | $params = {$params|@print_array}; | |
947a37b4 | 23 | {literal} |
0c13f046 | 24 | try{{/literal} |
a828d7b8 | 25 | $result = civicrm_api3('{$entity}', '{$action}', $params); |
0c13f046 EM |
26 | {literal} } |
27 | catch (CiviCRM_API3_Exception $e) { | |
28 | // Handle error here. | |
29 | $errorMessage = $e->getMessage(); | |
30 | $errorCode = $e->getErrorCode(); | |
31 | $errorData = $e->getExtraParams(); | |
8390b11b | 32 | return [ |
b5541920 MM |
33 | 'is_error' => 1, |
34 | 'error_message' => $errorMessage, | |
0c13f046 EM |
35 | 'error_code' => $errorCode, |
36 | 'error_data' => $errorData, | |
8390b11b | 37 | ]; |
0c13f046 | 38 | }{/literal} |
947a37b4 | 39 | |
0c13f046 | 40 | return $result; |
6a488035 TO |
41 | {literal}}{/literal} |
42 | ||
947a37b4 | 43 | /** |
0c13f046 EM |
44 | * Function returns array of result expected from previous function. |
45 | * | |
46 | * @return array | |
47 | * API result array | |
6a488035 | 48 | */ |
0c13f046 | 49 | function {$function}_expectedresult() {literal}{{/literal} |
6a488035 TO |
50 | |
51 | $expectedResult = {$result|@print_array}; | |
52 | ||
947a37b4 | 53 | return $expectedResult; |
6a488035 TO |
54 | {literal}}{/literal} |
55 | ||
a828d7b8 | 56 | /* |
0c13f046 | 57 | * This example has been generated from the API test suite. |
a828d7b8 CW |
58 | * The test that created it is called "{$testFunction}" |
59 | * and can be found at: | |
60 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/{$testFile} | |
6a488035 TO |
61 | * |
62 | * You can see the outcome of the API tests at | |
d25d2baa | 63 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
6a488035 TO |
64 | * |
65 | * To Learn about the API read | |
d25d2baa | 66 | * https://docs.civicrm.org/dev/en/latest/api/ |
6a488035 | 67 | * |
d25d2baa ML |
68 | * Browse the API on your own site with the API Explorer. It is in the main |
69 | * CiviCRM menu, under: Support > Development > API Explorer. | |
6a488035 TO |
70 | * |
71 | * Read more about testing here | |
d25d2baa | 72 | * https://docs.civicrm.org/dev/en/latest/testing/ |
6a488035 TO |
73 | * |
74 | * API Standards documentation: | |
d25d2baa | 75 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
fb32de45 | 76 | */ |