2b10ae16bfb1621b2864ba0b12d50386a2e56457
3 * Test Generated example demonstrating the Contact.getfields API.
5 * Demonstrates retrieving metadata with custom field options.
10 function contact_getfields_example() {
13 'get_options' => 'custom_1',
19 $result = civicrm_api3('Contact', 'getfields', $params);
21 catch (CiviCRM_API3_Exception
$e) {
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
27 'error' => $errorMessage,
28 'error_code' => $errorCode,
29 'error_data' => $errorData,
37 * Function returns array of result expected from previous function.
42 function contact_getfields_expectedresult() {
44 $expectedResult = array(
52 'title' => 'Internal Contact ID',
55 'where' => 'civicrm_contact.id',
56 'headerPattern' => '/internal|contact?|id$/i',
58 'api.aliases' => array(
62 'contact_type' => array(
63 'name' => 'contact_type',
65 'title' => 'Contact Type',
69 'where' => 'civicrm_contact.contact_type',
73 'pseudoconstant' => array(
74 'table' => 'civicrm_contact_type',
75 'keyColumn' => 'name',
76 'labelColumn' => 'label',
77 'condition' => 'parent_id IS NULL',
81 'contact_sub_type' => array(
82 'name' => 'contact_sub_type',
84 'title' => 'Contact Subtype',
88 'where' => 'civicrm_contact.contact_sub_type',
89 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
92 'type' => 'Multi-Select',
94 'pseudoconstant' => array(
95 'table' => 'civicrm_contact_type',
96 'keyColumn' => 'name',
97 'labelColumn' => 'label',
98 'condition' => 'parent_id IS NOT NULL',
101 'do_not_email' => array(
102 'name' => 'do_not_email',
104 'title' => 'Do Not Email',
106 'where' => 'civicrm_contact.do_not_email',
107 'headerPattern' => '/d(o )?(not )?(email)/i',
108 'dataPattern' => '/^\\d{1,}$/',
111 'type' => 'CheckBox',
114 'do_not_phone' => array(
115 'name' => 'do_not_phone',
117 'title' => 'Do Not Phone',
119 'where' => 'civicrm_contact.do_not_phone',
120 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
121 'dataPattern' => '/^\\d{1,}$/',
124 'type' => 'CheckBox',
127 'do_not_mail' => array(
128 'name' => 'do_not_mail',
130 'title' => 'Do Not Mail',
132 'where' => 'civicrm_contact.do_not_mail',
133 'headerPattern' => '/^(d(o\\s)?n(ot\\s)?mail)|(\\w*)?bulk\\s?(\\w*)$/i',
134 'dataPattern' => '/^\\d{1,}$/',
137 'type' => 'CheckBox',
140 'do_not_sms' => array(
141 'name' => 'do_not_sms',
143 'title' => 'Do Not Sms',
145 'where' => 'civicrm_contact.do_not_sms',
146 'headerPattern' => '/d(o )?(not )?(sms)/i',
147 'dataPattern' => '/^\\d{1,}$/',
150 'type' => 'CheckBox',
153 'do_not_trade' => array(
154 'name' => 'do_not_trade',
156 'title' => 'Do Not Trade',
158 'where' => 'civicrm_contact.do_not_trade',
159 'headerPattern' => '/d(o )?(not )?(trade)/i',
160 'dataPattern' => '/^\\d{1,}$/',
163 'type' => 'CheckBox',
166 'is_opt_out' => array(
167 'name' => 'is_opt_out',
169 'title' => 'No Bulk Emails (User Opt Out)',
172 'where' => 'civicrm_contact.is_opt_out',
175 'type' => 'CheckBox',
178 'legal_identifier' => array(
179 'name' => 'legal_identifier',
181 'title' => 'Legal Identifier',
185 'where' => 'civicrm_contact.legal_identifier',
186 'headerPattern' => '/legal\\s?id/i',
187 'dataPattern' => '/\\w+?\\d{5,}/',
193 'external_identifier' => array(
194 'name' => 'external_identifier',
196 'title' => 'External Identifier',
200 'where' => 'civicrm_contact.external_identifier',
201 'headerPattern' => '/external\\s?id/i',
202 'dataPattern' => '/^\\d{11,}$/',
208 'sort_name' => array(
209 'name' => 'sort_name',
211 'title' => 'Sort Name',
215 'where' => 'civicrm_contact.sort_name',
220 'display_name' => array(
221 'name' => 'display_name',
223 'title' => 'Display Name',
227 'where' => 'civicrm_contact.display_name',
232 'nick_name' => array(
233 'name' => 'nick_name',
235 'title' => 'Nickname',
239 'where' => 'civicrm_contact.nick_name',
240 'headerPattern' => '/n(ick\\s)name|nick$/i',
241 'dataPattern' => '/^\\w+$/',
247 'legal_name' => array(
248 'name' => 'legal_name',
250 'title' => 'Legal Name',
254 'where' => 'civicrm_contact.legal_name',
255 'headerPattern' => '/^legal|(l(egal\\s)?name)$/i',
261 'image_URL' => array(
262 'name' => 'image_URL',
264 'title' => 'Image Url',
268 'where' => 'civicrm_contact.image_URL',
274 'preferred_communication_method' => array(
275 'name' => 'preferred_communication_method',
277 'title' => 'Preferred Communication Method',
281 'where' => 'civicrm_contact.preferred_communication_method',
282 'headerPattern' => '/^p(ref\\w*\\s)?c(omm\\w*)|( meth\\w*)$/i',
283 'dataPattern' => '/^\\w+$/',
288 'pseudoconstant' => array(
289 'optionGroupName' => 'preferred_communication_method',
292 'preferred_language' => array(
293 'name' => 'preferred_language',
295 'title' => 'Preferred Language',
299 'where' => 'civicrm_contact.preferred_language',
300 'headerPattern' => '/^lang/i',
305 'pseudoconstant' => array(
306 'optionGroupName' => 'languages',
307 'keyColumn' => 'name',
310 'preferred_mail_format' => array(
311 'name' => 'preferred_mail_format',
313 'title' => 'Preferred Mail Format',
317 'where' => 'civicrm_contact.preferred_mail_format',
318 'headerPattern' => '/^p(ref\\w*\\s)?m(ail\\s)?f(orm\\w*)$/i',
324 'pseudoconstant' => array(
325 'callback' => 'CRM_Core_SelectValues::pmf',
331 'title' => 'Contact Hash',
335 'where' => 'civicrm_contact.hash',
340 'title' => 'Api Key',
344 'first_name' => array(
345 'name' => 'first_name',
347 'title' => 'First Name',
351 'where' => 'civicrm_contact.first_name',
352 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
353 'dataPattern' => '/^\\w+$/',
359 'middle_name' => array(
360 'name' => 'middle_name',
362 'title' => 'Middle Name',
366 'where' => 'civicrm_contact.middle_name',
367 'headerPattern' => '/^middle|(m(iddle\\s)?name)$/i',
368 'dataPattern' => '/^\\w+$/',
374 'last_name' => array(
375 'name' => 'last_name',
377 'title' => 'Last Name',
381 'where' => 'civicrm_contact.last_name',
382 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
383 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
389 'prefix_id' => array(
390 'name' => 'prefix_id',
392 'title' => 'Individual Prefix',
394 'where' => 'civicrm_contact.prefix_id',
395 'headerPattern' => '/^(prefix|title)/i',
396 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\\.?$/i',
401 'pseudoconstant' => array(
402 'optionGroupName' => 'individual_prefix',
404 'api.aliases' => array(
405 '0' => 'individual_prefix',
406 '1' => 'individual_prefix_id',
409 'suffix_id' => array(
410 'name' => 'suffix_id',
412 'title' => 'Individual Suffix',
414 'where' => 'civicrm_contact.suffix_id',
415 'headerPattern' => '/^suffix$/i',
416 'dataPattern' => '/^(sr|jr)\\.?|i{2,}$/',
421 'pseudoconstant' => array(
422 'optionGroupName' => 'individual_suffix',
424 'api.aliases' => array(
425 '0' => 'individual_suffix',
426 '1' => 'individual_suffix_id',
429 'formal_title' => array(
430 'name' => 'formal_title',
432 'title' => 'Formal Title',
436 'where' => 'civicrm_contact.formal_title',
437 'headerPattern' => '/^title/i',
440 'communication_style_id' => array(
441 'name' => 'communication_style_id',
443 'title' => 'Communication Style',
445 'where' => 'civicrm_contact.communication_style_id',
446 'pseudoconstant' => array(
447 'optionGroupName' => 'communication_style',
450 'email_greeting_id' => array(
451 'name' => 'email_greeting_id',
453 'title' => 'Email Greeting ID',
455 'email_greeting_custom' => array(
456 'name' => 'email_greeting_custom',
458 'title' => 'Email Greeting Custom',
462 'where' => 'civicrm_contact.email_greeting_custom',
467 'email_greeting_display' => array(
468 'name' => 'email_greeting_display',
470 'title' => 'Email Greeting',
477 'postal_greeting_id' => array(
478 'name' => 'postal_greeting_id',
480 'title' => 'Postal Greeting ID',
485 'postal_greeting_custom' => array(
486 'name' => 'postal_greeting_custom',
488 'title' => 'Postal Greeting Custom',
492 'where' => 'civicrm_contact.postal_greeting_custom',
497 'postal_greeting_display' => array(
498 'name' => 'postal_greeting_display',
500 'title' => 'Postal Greeting',
507 'addressee_id' => array(
508 'name' => 'addressee_id',
510 'title' => 'Addressee ID',
512 'addressee_custom' => array(
513 'name' => 'addressee_custom',
515 'title' => 'Addressee Custom',
519 'where' => 'civicrm_contact.addressee_custom',
524 'addressee_display' => array(
525 'name' => 'addressee_display',
527 'title' => 'Addressee',
534 'job_title' => array(
535 'name' => 'job_title',
537 'title' => 'Job Title',
541 'where' => 'civicrm_contact.job_title',
542 'headerPattern' => '/^job|(j(ob\\s)?title)$/i',
543 'dataPattern' => '//',
549 'gender_id' => array(
550 'name' => 'gender_id',
554 'where' => 'civicrm_contact.gender_id',
555 'headerPattern' => '/^gender$/i',
560 'pseudoconstant' => array(
561 'optionGroupName' => 'gender',
564 'birth_date' => array(
565 'name' => 'birth_date',
567 'title' => 'Birth Date',
569 'where' => 'civicrm_contact.birth_date',
570 'headerPattern' => '/^birth|(b(irth\\s)?date)|D(\\W*)O(\\W*)B(\\W*)$/i',
571 'dataPattern' => '/\\d{4}-?\\d{2}-?\\d{2}/',
574 'type' => 'Select Date',
577 'is_deceased' => array(
578 'name' => 'is_deceased',
580 'title' => 'Deceased',
582 'where' => 'civicrm_contact.is_deceased',
583 'headerPattern' => '/i(s\\s)?d(eceased)$/i',
586 'type' => 'CheckBox',
589 'deceased_date' => array(
590 'name' => 'deceased_date',
592 'title' => 'Deceased Date',
594 'where' => 'civicrm_contact.deceased_date',
595 'headerPattern' => '/^deceased|(d(eceased\\s)?date)$/i',
598 'type' => 'Select Date',
601 'household_name' => array(
602 'name' => 'household_name',
604 'title' => 'Household Name',
608 'where' => 'civicrm_contact.household_name',
609 'headerPattern' => '/^household|(h(ousehold\\s)?name)$/i',
610 'dataPattern' => '/^\\w+$/',
616 'primary_contact_id' => array(
617 'name' => 'primary_contact_id',
619 'title' => 'Household Primary Contact ID',
620 'FKClassName' => 'CRM_Contact_DAO_Contact',
624 'FKApiName' => 'Contact',
626 'organization_name' => array(
627 'name' => 'organization_name',
629 'title' => 'Organization Name',
633 'where' => 'civicrm_contact.organization_name',
634 'headerPattern' => '/^organization|(o(rganization\\s)?name)$/i',
635 'dataPattern' => '/^\\w+$/',
642 'name' => 'sic_code',
644 'title' => 'Sic Code',
648 'where' => 'civicrm_contact.sic_code',
649 'headerPattern' => '/^sic|(s(ic\\s)?code)$/i',
655 'user_unique_id' => array(
656 'name' => 'user_unique_id',
658 'title' => 'Unique ID (OpenID)',
662 'where' => 'civicrm_contact.user_unique_id',
663 'headerPattern' => '/^Open\\s?ID|u(niq\\w*)?\\s?ID/i',
664 'dataPattern' => '/^[\\w\\/\\:\\.]+$/',
671 'created_date' => array(
672 'name' => 'created_date',
674 'title' => 'Created Date',
677 'where' => 'civicrm_contact.created_date',
680 'modified_date' => array(
681 'name' => 'modified_date',
683 'title' => 'Modified Date',
686 'where' => 'civicrm_contact.modified_date',
687 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
692 'title' => 'Contact Source',
696 'where' => 'civicrm_contact.source',
697 'headerPattern' => '/(S(ource\\s)?o(f\\s)?C(ontact\\s)?Data)$/i',
702 'uniqueName' => 'contact_source',
704 'employer_id' => array(
705 'name' => 'employer_id',
707 'title' => 'Current Employer ID',
709 'where' => 'civicrm_contact.employer_id',
710 'FKClassName' => 'CRM_Contact_DAO_Contact',
712 'type' => 'Autocomplete-Select',
714 'uniqueName' => 'current_employer_id',
715 'FKApiName' => 'Contact',
717 'is_deleted' => array(
718 'name' => 'is_deleted',
720 'title' => 'Contact is in Trash',
723 'where' => 'civicrm_contact.is_deleted',
725 'type' => 'CheckBox',
727 'uniqueName' => 'contact_is_deleted',
730 'label' => 'Our special field',
731 'groupTitle' => 'select_test_g',
732 'data_type' => 'String',
733 'html_type' => 'Select',
734 'default_value' => '',
736 'options_per_line' => '',
737 'custom_group_id' => '1',
738 'extends' => 'Contact',
739 'is_search_range' => 0,
740 'extends_entity_column_value' => '',
741 'extends_entity_column_id' => '',
744 'option_group_id' => '106',
747 'is_required' => '1',
748 'name' => 'custom_1',
749 'title' => 'Our special field',
756 'current_employer' => array(
757 'title' => 'Current Employer',
758 'description' => 'Name of Current Employer',
760 'name' => 'current_employer',
762 'dupe_check' => array(
763 'title' => 'Check for Duplicates',
764 'description' => 'Throw error if contact create matches dedupe rule',
765 'name' => 'dupe_check',
770 return $expectedResult;
774 * This example has been generated from the API test suite.
775 * The test that created it is called "testCustomFieldCreateWithOptionValues"
776 * and can be found at:
777 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
779 * You can see the outcome of the API tests at
780 * https://test.civicrm.org/job/CiviCRM-master-git/
782 * To Learn about the API read
783 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
785 * Browse the api on your own site with the api explorer
786 * http://MYSITE.ORG/path/to/civicrm/api
788 * Read more about testing here
789 * http://wiki.civicrm.org/confluence/display/CRM/Testing
791 * API Standards documentation:
792 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards