| 1 | {literal}<?php{/literal} |
| 2 | /** |
| 3 | * Test Generated example demonstrating the {$entity}.{$action} API. |
| 4 | * |
| 5 | {if !empty($result.deprecated) && is_string($result.deprecated)} |
| 6 | * @deprecated |
| 7 | * {$result.deprecated} |
| 8 | {if !$description} |
| 9 | * |
| 10 | {/if} |
| 11 | {/if} |
| 12 | {if $description} |
| 13 | {foreach from=$description item='line'} |
| 14 | * {$line} |
| 15 | {/foreach} |
| 16 | * |
| 17 | {/if} |
| 18 | * @return array |
| 19 | * API result array |
| 20 | */ |
| 21 | function {$function}_example() {literal}{{/literal} |
| 22 | $params = {$params|@print_array}; |
| 23 | {literal} |
| 24 | try{{/literal} |
| 25 | $result = civicrm_api3('{$entity}', '{$action}', $params); |
| 26 | {literal} } |
| 27 | catch (CiviCRM_API3_Exception $e) { |
| 28 | // Handle error here. |
| 29 | $errorMessage = $e->getMessage(); |
| 30 | $errorCode = $e->getErrorCode(); |
| 31 | $errorData = $e->getExtraParams(); |
| 32 | return [ |
| 33 | 'is_error' => 1, |
| 34 | 'error_message' => $errorMessage, |
| 35 | 'error_code' => $errorCode, |
| 36 | 'error_data' => $errorData, |
| 37 | ]; |
| 38 | }{/literal} |
| 39 | |
| 40 | return $result; |
| 41 | {literal}}{/literal} |
| 42 | |
| 43 | /** |
| 44 | * Function returns array of result expected from previous function. |
| 45 | * |
| 46 | * @return array |
| 47 | * API result array |
| 48 | */ |
| 49 | function {$function}_expectedresult() {literal}{{/literal} |
| 50 | |
| 51 | $expectedResult = {$result|@print_array}; |
| 52 | |
| 53 | return $expectedResult; |
| 54 | {literal}}{/literal} |
| 55 | |
| 56 | /* |
| 57 | * This example has been generated from the API test suite. |
| 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} |
| 61 | * |
| 62 | * You can see the outcome of the API tests at |
| 63 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
| 64 | * |
| 65 | * To Learn about the API read |
| 66 | * https://docs.civicrm.org/dev/en/latest/api/ |
| 67 | * |
| 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. |
| 70 | * |
| 71 | * Read more about testing here |
| 72 | * https://docs.civicrm.org/dev/en/latest/testing/ |
| 73 | * |
| 74 | * API Standards documentation: |
| 75 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
| 76 | */ |