fac0bae4e7eb9524e2ad6c61d0cec7a176e345d7
4 Demonstrate retrieving metadata with custom field options
6 function contact_getfields_example(){
9 'get_options' => 'custom_1',
15 $result = civicrm_api( 'contact','GetFields',$params );
21 * Function returns array of result expected from previous function
23 function contact_getfields_expectedresult(){
25 $expectedResult = array(
33 'title' => 'Internal Contact ID',
36 'where' => 'civicrm_contact.id',
37 'headerPattern' => '/internal|contact?|id$/i',
39 'api.aliases' => array(
43 'contact_type' => array(
44 'name' => 'contact_type',
46 'title' => 'Contact Type',
50 'where' => 'civicrm_contact.contact_type',
51 'pseudoconstant' => array(
52 'table' => 'civicrm_contact_type',
53 'keyColumn' => 'name',
54 'labelColumn' => 'label',
55 'condition' => 'parent_id IS NULL',
59 'contact_sub_type' => array(
60 'name' => 'contact_sub_type',
62 'title' => 'Contact Subtype',
66 'where' => 'civicrm_contact.contact_sub_type',
67 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
69 'pseudoconstant' => array(
70 'table' => 'civicrm_contact_type',
71 'keyColumn' => 'name',
72 'labelColumn' => 'label',
73 'condition' => 'parent_id IS NOT NULL',
76 'do_not_email' => array(
77 'name' => 'do_not_email',
79 'title' => 'Do Not Email',
81 'where' => 'civicrm_contact.do_not_email',
82 'headerPattern' => '/d(o )?(not )?(email)/i',
83 'dataPattern' => '/^\d{1,}$/',
86 'do_not_phone' => array(
87 'name' => 'do_not_phone',
89 'title' => 'Do Not Phone',
91 'where' => 'civicrm_contact.do_not_phone',
92 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
93 'dataPattern' => '/^\d{1,}$/',
96 'do_not_mail' => array(
97 'name' => 'do_not_mail',
99 'title' => 'Do Not Mail',
101 'where' => 'civicrm_contact.do_not_mail',
102 'headerPattern' => '/^(d(o\s)?n(ot\s)?mail)|(\w*)?bulk\s?(\w*)$/i',
103 'dataPattern' => '/^\d{1,}$/',
106 'do_not_sms' => array(
107 'name' => 'do_not_sms',
109 'title' => 'Do Not Sms',
111 'where' => 'civicrm_contact.do_not_sms',
112 'headerPattern' => '/d(o )?(not )?(sms)/i',
113 'dataPattern' => '/^\d{1,}$/',
116 'do_not_trade' => array(
117 'name' => 'do_not_trade',
119 'title' => 'Do Not Trade',
121 'where' => 'civicrm_contact.do_not_trade',
122 'headerPattern' => '/d(o )?(not )?(trade)/i',
123 'dataPattern' => '/^\d{1,}$/',
126 'is_opt_out' => array(
127 'name' => 'is_opt_out',
129 'title' => 'No Bulk Emails (User Opt Out)',
132 'where' => 'civicrm_contact.is_opt_out',
135 'legal_identifier' => array(
136 'name' => 'legal_identifier',
138 'title' => 'Legal Identifier',
142 'where' => 'civicrm_contact.legal_identifier',
143 'headerPattern' => '/legal\s?id/i',
144 'dataPattern' => '/\w+?\d{5,}/',
147 'external_identifier' => array(
148 'name' => 'external_identifier',
150 'title' => 'External Identifier',
154 'where' => 'civicrm_contact.external_identifier',
155 'headerPattern' => '/external\s?id/i',
156 'dataPattern' => '/^\d{11,}$/',
159 'sort_name' => array(
160 'name' => 'sort_name',
162 'title' => 'Sort Name',
166 'where' => 'civicrm_contact.sort_name',
168 'display_name' => array(
169 'name' => 'display_name',
171 'title' => 'Display Name',
175 'where' => 'civicrm_contact.display_name',
177 'nick_name' => array(
178 'name' => 'nick_name',
180 'title' => 'Nickname',
184 'where' => 'civicrm_contact.nick_name',
185 'headerPattern' => '/n(ick\s)name|nick$/i',
186 'dataPattern' => '/^\w+$/',
189 'legal_name' => array(
190 'name' => 'legal_name',
192 'title' => 'Legal Name',
196 'where' => 'civicrm_contact.legal_name',
197 'headerPattern' => '/^legal|(l(egal\s)?name)$/i',
200 'image_URL' => array(
201 'name' => 'image_URL',
203 'title' => 'Image Url',
207 'where' => 'civicrm_contact.image_URL',
210 'preferred_communication_method' => array(
211 'name' => 'preferred_communication_method',
213 'title' => 'Preferred Communication Method',
217 'where' => 'civicrm_contact.preferred_communication_method',
218 'headerPattern' => '/^p(ref\w*\s)?c(omm\w*)|( meth\w*)$/i',
219 'dataPattern' => '/^\w+$/',
221 'pseudoconstant' => array(
222 'optionGroupName' => 'preferred_communication_method',
225 'preferred_language' => array(
226 'name' => 'preferred_language',
228 'title' => 'Preferred Language',
232 'where' => 'civicrm_contact.preferred_language',
233 'headerPattern' => '/^lang/i',
235 'pseudoconstant' => array(
236 'optionGroupName' => 'languages',
237 'keyColumn' => 'name',
240 'preferred_mail_format' => array(
241 'name' => 'preferred_mail_format',
243 'title' => 'Preferred Mail Format',
245 'where' => 'civicrm_contact.preferred_mail_format',
246 'headerPattern' => '/^p(ref\w*\s)?m(ail\s)?f(orm\w*)$/i',
249 'enumValues' => 'Text, HTML, Both',
254 'title' => 'Contact Hash',
258 'where' => 'civicrm_contact.hash',
263 'title' => 'Api Key',
267 'first_name' => array(
268 'name' => 'first_name',
270 'title' => 'First Name',
274 'where' => 'civicrm_contact.first_name',
275 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
276 'dataPattern' => '/^\w+$/',
279 'middle_name' => array(
280 'name' => 'middle_name',
282 'title' => 'Middle Name',
286 'where' => 'civicrm_contact.middle_name',
287 'headerPattern' => '/^middle|(m(iddle\s)?name)$/i',
288 'dataPattern' => '/^\w+$/',
291 'last_name' => array(
292 'name' => 'last_name',
294 'title' => 'Last Name',
298 'where' => 'civicrm_contact.last_name',
299 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
300 'dataPattern' => '/^\w+(\s\w+)?+$/',
303 'prefix_id' => array(
304 'name' => 'prefix_id',
306 'title' => 'Individual Prefix',
308 'where' => 'civicrm_contact.prefix_id',
309 'headerPattern' => '/^(prefix|title)/i',
310 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\.?$/i',
312 'pseudoconstant' => array(
313 'optionGroupName' => 'individual_prefix',
316 'suffix_id' => array(
317 'name' => 'suffix_id',
319 'title' => 'Individual Suffix',
321 'where' => 'civicrm_contact.suffix_id',
322 'headerPattern' => '/^suffix$/i',
323 'dataPattern' => '/^(sr|jr)\.?|i{2,}$/',
325 'pseudoconstant' => array(
326 'optionGroupName' => 'individual_suffix',
329 'email_greeting_id' => array(
330 'name' => 'email_greeting_id',
332 'title' => 'Email Greeting ID',
334 'email_greeting_custom' => array(
335 'name' => 'email_greeting_custom',
337 'title' => 'Email Greeting Custom',
341 'where' => 'civicrm_contact.email_greeting_custom',
343 'email_greeting_display' => array(
344 'name' => 'email_greeting_display',
346 'title' => 'Email Greeting',
350 'postal_greeting_id' => array(
351 'name' => 'postal_greeting_id',
353 'title' => 'Postal Greeting ID',
355 'postal_greeting_custom' => array(
356 'name' => 'postal_greeting_custom',
358 'title' => 'Postal Greeting Custom',
362 'where' => 'civicrm_contact.postal_greeting_custom',
364 'postal_greeting_display' => array(
365 'name' => 'postal_greeting_display',
367 'title' => 'Postal Greeting',
371 'addressee_id' => array(
372 'name' => 'addressee_id',
374 'title' => 'Addressee ID',
376 'addressee_custom' => array(
377 'name' => 'addressee_custom',
379 'title' => 'Addressee Custom',
383 'where' => 'civicrm_contact.addressee_custom',
385 'addressee_display' => array(
386 'name' => 'addressee_display',
388 'title' => 'Addressee',
392 'job_title' => array(
393 'name' => 'job_title',
395 'title' => 'Job Title',
399 'where' => 'civicrm_contact.job_title',
400 'headerPattern' => '/^job|(j(ob\s)?title)$/i',
401 'dataPattern' => '//',
404 'gender_id' => array(
405 'name' => 'gender_id',
409 'where' => 'civicrm_contact.gender_id',
410 'headerPattern' => '/^gender$/i',
412 'pseudoconstant' => array(
413 'optionGroupName' => 'gender',
416 'birth_date' => array(
417 'name' => 'birth_date',
419 'title' => 'Birth Date',
421 'where' => 'civicrm_contact.birth_date',
422 'headerPattern' => '/^birth|(b(irth\s)?date)|D(\W*)O(\W*)B(\W*)$/i',
423 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
426 'is_deceased' => array(
427 'name' => 'is_deceased',
429 'title' => 'Is Deceased',
431 'where' => 'civicrm_contact.is_deceased',
432 'headerPattern' => '/i(s\s)?d(eceased)$/i',
435 'deceased_date' => array(
436 'name' => 'deceased_date',
438 'title' => 'Deceased Date',
440 'where' => 'civicrm_contact.deceased_date',
441 'headerPattern' => '/^deceased|(d(eceased\s)?date)$/i',
444 'household_name' => array(
445 'name' => 'household_name',
447 'title' => 'Household Name',
451 'where' => 'civicrm_contact.household_name',
452 'headerPattern' => '/^household|(h(ousehold\s)?name)$/i',
453 'dataPattern' => '/^\w+$/',
456 'primary_contact_id' => array(
457 'name' => 'primary_contact_id',
459 'title' => 'Household Primary Contact ID',
460 'FKClassName' => 'CRM_Contact_DAO_Contact',
462 'organization_name' => array(
463 'name' => 'organization_name',
465 'title' => 'Organization Name',
469 'where' => 'civicrm_contact.organization_name',
470 'headerPattern' => '/^organization|(o(rganization\s)?name)$/i',
471 'dataPattern' => '/^\w+$/',
475 'name' => 'sic_code',
477 'title' => 'Sic Code',
481 'where' => 'civicrm_contact.sic_code',
482 'headerPattern' => '/^sic|(s(ic\s)?code)$/i',
485 'user_unique_id' => array(
486 'name' => 'user_unique_id',
488 'title' => 'Unique ID (OpenID)',
492 'where' => 'civicrm_contact.user_unique_id',
493 'headerPattern' => '/^Open\s?ID|u(niq\w*)?\s?ID/i',
494 'dataPattern' => '/^[\w\/\:\.]+$/',
498 'created_date' => array(
499 'name' => 'created_date',
501 'title' => 'Created Date',
505 'modified_date' => array(
506 'name' => 'modified_date',
508 'title' => 'Modified Date',
510 'default' => 'URRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM',
515 'title' => 'Source of Contact Data',
519 'where' => 'civicrm_contact.source',
520 'headerPattern' => '/(S(ource\s)?o(f\s)?C(ontact\s)?Data)$/i',
522 'uniqueName' => 'contact_source',
524 'employer_id' => array(
525 'name' => 'employer_id',
527 'title' => 'Current Employer ID',
529 'where' => 'civicrm_contact.employer_id',
530 'FKClassName' => 'CRM_Contact_DAO_Contact',
531 'uniqueName' => 'current_employer_id',
533 'is_deleted' => array(
534 'name' => 'is_deleted',
536 'title' => 'Contact is in Trash',
539 'where' => 'civicrm_contact.is_deleted',
540 'uniqueName' => 'contact_is_deleted',
543 'label' => 'Our special field',
544 'groupTitle' => 'select_test_g',
545 'data_type' => 'String',
546 'html_type' => 'Select',
548 'options_per_line' => '',
549 'custom_group_id' => '1',
550 'extends' => 'Contact',
551 'is_search_range' => 0,
552 'extends_entity_column_value' => '',
553 'extends_entity_column_id' => '',
556 'option_group_id' => '97',
559 'name' => 'custom_1',
565 'current_employer' => array(
566 'title' => 'Current Employer',
567 'description' => 'Name of Current Employer',
569 'dupe_check' => array(
570 'title' => 'Check for Duplicates',
571 'description' => 'Throw error if contact create matches dedupe rule',
576 return $expectedResult ;
581 * This example has been generated from the API test suite. The test that created it is called
583 * testCustomFieldCreateWithOptionValues and can be found in
584 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
586 * You can see the outcome of the API tests at
587 * http://tests.dev.civicrm.org/trunk/results-api_v3
589 * To Learn about the API read
590 * http://book.civicrm.org/developer/current/techniques/api/
592 * and review the wiki at
593 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
595 * Read more about testing here
596 * http://wiki.civicrm.org/confluence/display/CRM/Testing
598 * API Standards documentation:
599 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards