updated examples
[civicrm-core.git] / api / v3 / examples / CustomFieldCreate.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using custom_field create API
4 * *
6a488035 5 */
fb32de45 6function custom_field_create_example(){
7$params = array(
8 'custom_group_id' => 1,
9 'name' => 'test_textfield2',
10 'label' => 'Name1',
11 'html_type' => 'Text',
12 'data_type' => 'String',
13 'default_value' => 'abc',
14 'weight' => 4,
15 'is_required' => 1,
16 'is_searchable' => 0,
17 'is_active' => 1,
18);
6a488035 19
fb32de45 20try{
21 $result = civicrm_api3('custom_field', 'create', $params);
22}
23catch (CiviCRM_API3_Exception $e) {
24 // handle error here
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
29}
6a488035 30
fb32de45 31return $result;
6a488035
TO
32}
33
fb32de45 34/**
6a488035
TO
35 * Function returns array of result expected from previous function
36 */
fb32de45 37function custom_field_create_expectedresult(){
6a488035
TO
38
39 $expectedResult = array(
fb32de45 40 'is_error' => 0,
41 'version' => 3,
42 'count' => 1,
43 'id' => 1,
44 'values' => array(
6a488035 45 '1' => array(
fb32de45 46 'id' => '1',
47 'custom_group_id' => '1',
b422b715 48 'name' => 'test_textfield2',
fb32de45 49 'label' => 'Name1',
50 'data_type' => 'String',
51 'html_type' => 'Text',
52 'default_value' => 'abc',
53 'is_required' => '1',
54 'is_searchable' => 0,
55 'is_search_range' => 0,
56 'weight' => '4',
57 'help_pre' => '',
58 'help_post' => '',
59 'mask' => '',
60 'attributes' => '',
61 'javascript' => '',
62 'is_active' => '1',
63 'is_view' => 0,
64 'options_per_line' => '',
65 'text_length' => '',
66 'start_date_years' => '',
67 'end_date_years' => '',
68 'date_format' => '',
69 'time_format' => '',
70 'note_columns' => '',
71 'note_rows' => '',
72 'column_name' => 'name1_1',
73 'option_group_id' => '',
74 'filter' => '',
75 ),
6a488035 76 ),
fb32de45 77);
6a488035
TO
78
79 return $expectedResult;
80}
81
82
6a488035
TO
83/*
84* This example has been generated from the API test suite. The test that created it is called
fb32de45 85*
86* testCustomFieldCreateWithEdit and can be found in
87* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/CustomFieldTest.php
88*
1c88e578 89* You can see the outcome of the API tests at
6a488035 90* http://tests.dev.civicrm.org/trunk/results-api_v3
fb32de45 91*
92* To Learn about the API read
93* http://book.civicrm.org/developer/current/techniques/api/
94*
6a488035 95* and review the wiki at
fb32de45 96* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
97*
6a488035
TO
98* Read more about testing here
99* http://wiki.civicrm.org/confluence/display/CRM/Testing
fb32de45 100*
101* API Standards documentation:
102* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 103*/