function wf_crm_get_fields in Webform CiviCRM Integration 7.3
Same name and namespace in other branches
- 7.5 includes/utils.inc \wf_crm_get_fields()
- 7.4 includes/utils.inc \wf_crm_get_fields()
Fetches CiviCRM field data.
Parameters
$var: Name of variable to return: fields, tokens, lists, or sets
Return value
array fields: The CiviCRM contact fields this module supports tokens: Available tokens keyed to field ids lists: Option lists keyed to option_group name sets: Info on fieldsets (tables)
16 calls to wf_crm_get_fields()
- theme_webform_civicrm_components_form in ./
webform_civicrm_admin.inc - Theme override for webform components form.
- webform_civicrm_update_6200 in ./
webform_civicrm.install - Upgrade from 1.x to 2.x Add columns to webform_civicrm_forms table, and convert existing forms to new multi-entity schema.
- webform_civicrm_update_7300 in ./
webform_civicrm.install - Note: There are differences in how contact references and relationships work in the 3.x branch. Read the upgrade instructions at http://drupal.org/node/1615380
- wf_crm_configure_form in ./
webform_civicrm_admin.inc - Drupal form builder callback Form to configure CiviCRM options for a Webform
- wf_crm_configure_form_submit in ./
webform_civicrm_admin.inc - Submission handler, saves CiviCRM options for a Webform node
File
- ./
webform_civicrm_utils.inc, line 549 - Webform CiviCRM module's common utility functions.
Code
function wf_crm_get_fields($var = 'fields') {
static $fields = array();
static $tokens = array();
static $lists = array();
static $sets = array();
if (!$fields) {
require_once 'CRM/Core/BAO/Tag.php';
$config = CRM_Core_Config::singleton();
$components = $config->enableComponents;
// key: table_fieldname (table can be a * wildcard)
// value: name of civicrm_option_group
$lists = array(
'contact_contact_sub_type' => 'contact_sub_type',
'contact_prefix_id' => 'individual_prefix',
'contact_suffix_id' => 'individual_suffix',
'contact_gender_id' => 'gender',
'contact_preferred_communication_method' => 'preferred_communication_method',
'contact_preferred_language' => 'languages',
'contact_privacy' => 'privacy',
'contact_employer_id' => 'organization',
'*_country_id' => 'country',
'*_county_id' => 'county',
'phone_phone_type_id' => 'phone_type',
'*_location_type_id' => 'location_type',
'website_website_type_id' => 'website_type',
'address_master_id' => 'contact',
'activity_target_contact_id' => 'contact',
'activity_assignee_contact_id' => 'contact',
'activity_status_id' => 'activity_status',
'activity_priority_id' => 'priority',
'*_engagement_level' => 'engagement_index',
'relationship_relationship_type_id' => 'relationship_type_id',
'relationship_is_active' => 'yes_no',
'relationship_relationship_permission' => 'relationship_permission',
'*_group' => 'group',
'case_client_id' => 'contact',
'case_creator_id' => 'contact',
'case_status_id' => 'case_status',
'case_medium_id' => 'encounter_medium',
'participant_event_id' => 'event',
'participant_role_id' => 'participant_role',
'participant_status_id' => 'participant_status',
'*_campaign_id' => 'campaign',
'*_survey_id' => 'survey',
);
// Field keys are in the format table_column
// Use a # sign as a placeholder for field number in the title (or by default it will be appended to the end)
// Setting 'expose_list' allows the value to be set on the config form
// Set label for 'empty_option' for exposed lists that do not require input
$fields['contact_contact_sub_type'] = array(
'name' => t('Type of'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
'civicrm_live_options' => 1,
),
'expose_list' => TRUE,
);
$fields['contact_existing'] = array(
'name' => t('Existing Contact'),
'type' => 'civicrm_contact',
'extra' => array(
'search_prompt' => t('- Choose existing contact -'),
),
);
foreach (array(
'organization' => t('Organization Name'),
'legal' => t('Legal Name'),
'household' => t('Household Name'),
) as $key => $label) {
$fields['contact_' . $key . '_name'] = array(
'name' => $label,
'type' => 'textfield',
'contact_type' => $key == 'household' ? 'household' : 'organization',
);
}
foreach (array(
'first_name' => t('First Name'),
'nick_name' => t('Nickname'),
'middle_name' => t('Middle Name'),
'last_name' => t('Last Name'),
'job_title' => t('Job Title'),
) as $key => $label) {
$fields['contact_' . $key] = array(
'name' => $label,
'type' => 'textfield',
'contact_type' => $key == 'nick_name' ? NULL : 'individual',
);
}
foreach (array(
'prefix' => t('Name Prefix'),
'suffix' => t('Name Suffix'),
'gender' => t('Gender'),
) as $key => $label) {
$fields['contact_' . $key . '_id'] = array(
'name' => $label,
'type' => 'select',
'contact_type' => 'individual',
);
}
$fields['contact_birth_date'] = array(
'name' => t('Birth Date'),
'type' => 'date',
'extra' => array(
'start_date' => '-100 years',
'end_date' => 'now',
),
'contact_type' => 'individual',
);
$fields['contact_preferred_communication_method'] = array(
'name' => t('Preferred Communication Method(s)'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
);
$fields['contact_privacy'] = array(
'name' => t('Privacy Preferences'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
);
$fields['contact_preferred_language'] = array(
'name' => t('Preferred Language'),
'type' => 'select',
'value' => $config->lcMessages,
);
if (array_key_exists('file', webform_components())) {
$fields['contact_image_URL'] = array(
'name' => t('Upload Image'),
'type' => 'file',
'extra' => array(
'width' => 40,
),
);
}
$fields['contact_contact_id'] = array(
'name' => t('Contact ID'),
'type' => 'hidden',
'extra' => array(
'description' => t('(hidden field, use for post-processing)'),
),
);
$fields['contact_external_identifier'] = array(
'name' => t('External ID'),
'type' => 'hidden',
'extra' => array(
'description' => t('(hidden field, use for post-processing)'),
),
);
$fields['contact_cs'] = array(
'name' => t('Checksum'),
'type' => 'hidden',
'extra' => array(
'description' => t('(hidden field, use to create hashed links)'),
),
);
$fields['contact_employer_id'] = array(
'name' => t('Current Employer'),
'type' => 'select',
'expose_list' => TRUE,
'empty_option' => t('None'),
'data_type' => 'ContactReference',
'contact_type' => 'individual',
);
$fields['email_email'] = array(
'name' => t('Email'),
'type' => 'email',
);
foreach (array(
'street_address' => t('Street Address'),
'supplemental_address_1' => t('Street Address # Line 2'),
'supplemental_address_2' => t('Street Address # Line 3'),
'city' => t('City'),
) as $key => $value) {
$fields['address_' . $key] = array(
'name' => $value,
'type' => 'textfield',
'extra' => array(
'width' => $key == 'city' ? 20 : 60,
),
);
}
$fields['address_postal_code'] = array(
'name' => t('Postal Code'),
'type' => 'textfield',
'extra' => array(
'width' => 7,
),
);
$fields['address_postal_code_suffix'] = array(
'name' => t('Postal Code Suffix'),
'type' => 'textfield',
'extra' => array(
'width' => 5,
'description' => t('+4 digits of Zip Code'),
),
);
$fields['address_county_id'] = array(
'name' => t('District/County'),
'type' => 'textfield',
);
$fields['address_country_id'] = array(
'name' => t('Country'),
'type' => 'select',
'extra' => array(
'civicrm_live_options' => 1,
),
'value' => $config->defaultContactCountry,
);
$fields['address_state_province_id'] = array(
'name' => t('State/Province'),
'type' => 'textfield',
'extra' => array(
'maxlength' => 5,
'width' => 4,
),
'data_type' => 'state_province_abbr',
);
$fields['address_master_id'] = array(
'name' => t('Share address of'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array(
'description' => t('Will overwrite address fields with those of the other contact.'),
),
'empty_option' => t('Do Not Share'),
);
$fields['phone_phone'] = array(
'name' => t('Phone Number'),
'type' => 'textfield',
);
$fields['phone_phone_ext'] = array(
'name' => t('Phone Extension'),
'type' => 'textfield',
'extra' => array(
'width' => 4,
),
);
$fields['phone_phone_type_id'] = array(
'name' => t('Phone # Type'),
'type' => 'select',
'table' => 'phone',
'expose_list' => TRUE,
);
foreach (array(
'address' => t('Address # Location'),
'phone' => t('Phone # Location'),
'email' => t('Email # Location'),
) as $key => $label) {
$fields[$key . '_location_type_id'] = array(
'name' => $label,
'type' => 'select',
'expose_list' => TRUE,
'value' => '1',
);
}
$fields['website_url'] = array(
'name' => t('Website'),
'type' => 'textfield',
'data_type' => 'Link',
);
$fields['website_website_type_id'] = array(
'name' => t('Website # Type'),
'type' => 'select',
'expose_list' => TRUE,
);
$fields['other_group'] = array(
'name' => t('Groups'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
'civicrm_live_options' => 1,
),
'table' => 'group',
'expose_list' => TRUE,
);
$tagsets = array(
'' => t('Tags'),
) + CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
foreach ($tagsets as $pid => $name) {
// Ensure getTagSet is actually returning ids, per CRM-10685 added to CiviCRM 4.1.6
if ($pid === 0) {
break;
}
$fields['other_tag' . ($pid ? "_{$pid}" : '')] = array(
'name' => $name,
'type' => 'select',
'extra' => array(
'multiple' => 1,
'civicrm_live_options' => 1,
),
'table' => 'tag',
'expose_list' => TRUE,
);
$lists['*_tag' . ($pid ? "_{$pid}" : '')] = 'tag';
}
$fields['activity_target_contact_id'] = array(
'name' => t('Activity Participants'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array(
'multiple' => 1,
'description' => t('Which contacts should be tagged as part of this activity?'),
),
'data_type' => 'ContactReference',
);
$fields['activity_subject'] = array(
'name' => t('Activity Subject'),
'type' => 'textfield',
);
$fields['activity_details'] = array(
'name' => t('Activity Details'),
'type' => module_exists('webform_html_textarea') ? 'html_textarea' : 'textarea',
);
foreach (array(
'status' => t('Activity Status'),
'priority' => t('Activity Priority'),
) as $key => $label) {
$fields['activity_' . $key . '_id'] = array(
'name' => $label,
'type' => 'select',
'value' => '2',
'expose_list' => TRUE,
);
}
$fields['activity_assignee_contact_id'] = array(
'name' => t('Assign Activity to'),
'type' => 'select',
'expose_list' => TRUE,
'empty_option' => t('No One'),
'data_type' => 'ContactReference',
);
$fields['activity_location'] = array(
'name' => t('Activity Location'),
'type' => 'textfield',
);
$fields['activity_activity_date_time'] = array(
'name' => t('Activity Date'),
'type' => 'date',
);
$fields['activity_activity_date_time_timepart'] = array(
'name' => t('Activity Time'),
'type' => 'time',
);
$fields['activity_duration'] = array(
'name' => t('Duration'),
'type' => 'number',
'extra' => array(
'description' => t('Total time spent on this activity (in minutes).'),
'field_suffix' => t('min.'),
'min' => 0,
'step' => 5,
'integer' => 1,
),
);
$fields['activity_engagement_level'] = array(
'name' => t('Engagement Level'),
'type' => 'select',
'empty_option' => t('None'),
'expose_list' => TRUE,
);
if (in_array('CiviCampaign', $components)) {
$fields['activity_campaign_id'] = array(
'name' => t('Campaign'),
'type' => 'select',
'expose_list' => TRUE,
'empty_option' => t('None'),
'extra' => array(
'civicrm_live_options' => 1,
),
);
$fields['activity_survey_id'] = array(
'name' => t('Survey/Petition'),
'type' => 'select',
'expose_list' => TRUE,
'empty_option' => t('None'),
'extra' => array(
'civicrm_live_options' => 1,
),
);
}
if (in_array('CiviCase', $components)) {
require_once 'CRM/Case/XMLProcessor/Process.php';
$case_info = new CRM_Case_XMLProcessor_Process();
$fields['case_client_id'] = array(
'name' => t('Case Client'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array(
'mandatory' => 1,
'multiple' => $case_info
->getAllowMultipleCaseClients(),
),
'data_type' => 'ContactReference',
'value' => 1,
);
$fields['case_status_id'] = array(
'name' => t('Case Status'),
'type' => 'select',
'expose_list' => TRUE,
);
$fields['case_medium_id'] = array(
'name' => t('Medium'),
'type' => 'select',
'extra' => array(
'description' => t('Medium for activities added to cases from this webform.'),
),
'expose_list' => TRUE,
);
$fields['case_subject'] = array(
'name' => t('Case Subject'),
'type' => 'textfield',
);
$fields['case_creator_id'] = array(
'name' => t('Case Manager'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array(
'description' => t('Owner of newly created cases.'),
),
'data_type' => 'ContactReference',
);
}
$fields['relationship_relationship_type_id'] = array(
'name' => t('Relationship to Contact #'),
'type' => 'select',
'expose_list' => TRUE,
'empty_option' => t('No Relationship'),
'extra' => array(
'civicrm_live_options' => 1,
),
);
$fields['relationship_is_active'] = array(
'name' => t('Relationship to Contact # Is Active'),
'type' => 'select',
'expose_list' => TRUE,
'value' => '1',
);
$fields['relationship_relationship_permission'] = array(
'name' => t('Relationship to Contact # Permission'),
'type' => 'select',
'expose_list' => TRUE,
'empty_option' => t('No Permissions'),
);
$fields['relationship_start_date'] = array(
'name' => t('Relationship to Contact # Start Date'),
'type' => 'date',
'extra' => array(
'start_date' => '-50 years',
'end_date' => '+10 years',
),
);
$fields['relationship_end_date'] = array(
'name' => t('Relationship to Contact # End Date'),
'type' => 'date',
'extra' => array(
'start_date' => '-50 years',
'end_date' => '+10 years',
),
);
$fields['relationship_description'] = array(
'name' => t('Relationship to Contact # Description'),
'type' => 'textarea',
);
if (in_array('CiviEvent', $components)) {
$fields['participant_event_id'] = array(
'name' => t('Events'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
'civicrm_live_options' => 1,
),
'expose_list' => TRUE,
);
$fields['participant_role_id'] = array(
'name' => t('Participant Role'),
'type' => 'select',
'expose_list' => TRUE,
'value' => '1',
);
$fields['participant_status_id'] = array(
'name' => t('Registration Status'),
'type' => 'select',
'expose_list' => TRUE,
'value' => '1',
);
if (in_array('CiviCampaign', $components)) {
$fields['participant_campaign_id'] = array(
'name' => t('Campaign'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array(
'civicrm_live_options' => 1,
),
'empty_option' => t('None'),
);
}
}
$tokens = array(
'display_name' => t('display name'),
'first_name' => t('first name'),
'nick_name' => t('nickname'),
'middle_name' => t('middle name'),
'last_name' => t('last name'),
'individual_prefix' => t('name prefix'),
'individual_suffix' => t('name suffix'),
'gender' => t('gender'),
'birth_date' => t('birth date'),
'job_title' => t('job title'),
'current_employer' => t('current employer'),
'contact_id' => t('contact id'),
'street_address' => t('street address'),
'city' => t('city'),
'state_province' => t('state/province abbr'),
'state_province_name' => t('state/province full'),
'postal_code' => t('postal code'),
'country' => t('country'),
'world_region' => t('world region'),
'phone' => t('phone number'),
'email' => t('email'),
);
$sets = array(
'contact' => array(
'entity_type' => 'contact',
'label' => t('Contact Fields'),
),
'other' => array(
'entity_type' => 'contact',
'label' => t('Tags and Groups'),
'max_instances' => 1,
),
'address' => array(
'entity_type' => 'contact',
'label' => t('Address'),
'max_instances' => 9,
),
'phone' => array(
'entity_type' => 'contact',
'label' => t('Phone'),
'max_instances' => 9,
),
'email' => array(
'entity_type' => 'contact',
'label' => t('Email'),
'max_instances' => 9,
),
'website' => array(
'entity_type' => 'contact',
'label' => t('Website'),
'max_instances' => 9,
),
'activity' => array(
'entity_type' => 'activity',
'label' => t('Activity'),
),
'relationship' => array(
'entity_type' => 'contact',
'label' => t('Relationship to Contact'),
),
);
if (in_array('CiviCase', $components)) {
$sets['case'] = array(
'entity_type' => 'case',
'label' => t('Case Settings'),
);
}
if (in_array('CiviEvent', $components)) {
$sets['participant'] = array(
'entity_type' => 'participant',
'label' => t('Participant'),
'max_instances' => 9,
);
}
// Pull custom fields and match to Webform element types
$custom_types = array(
'Select' => array(
'type' => 'select',
),
'Multi-Select' => array(
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
),
'AdvMulti-Select' => array(
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
),
'Radio' => array(
'type' => 'select',
'extra' => array(
'aslist' => 0,
),
),
'CheckBox' => array(
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
),
'Text' => array(
'type' => 'textfield',
),
'TextArea' => array(
'type' => 'textarea',
),
'RichTextEditor' => array(
'type' => module_exists('webform_html_textarea') ? 'html_textarea' : 'textarea',
),
'Select Date' => array(
'type' => 'date',
),
'Link' => array(
'type' => 'textfield',
),
'Select Country' => array(
'type' => 'select',
),
'Multi-Select Country' => array(
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
),
'Select State/Province' => array(
'type' => 'select',
),
'Multi-Select State/Province' => array(
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
),
'Autocomplete-Select' => array(
'type' => 'select',
),
);
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
$custom_extends = "'contact','individual','organization','household','address','activity','relationship'";
if (in_array('CiviEvent', $components, TRUE)) {
$custom_extends .= ",'participant'";
}
if (in_array('CiviCase', $components, TRUE)) {
$custom_extends .= ",'case'";
}
$sql = "\n SELECT cf.*, cg.title AS custom_group_name, LOWER(cg.extends) AS entity_type, cg.extends_entity_column_id, cg.extends_entity_column_value AS sub_types, cg.is_multiple, cg.max_multiple, cg.id AS custom_group_id\n FROM civicrm_custom_field cf\n INNER JOIN civicrm_custom_group cg ON cg.id = cf.custom_group_id\n WHERE cf.is_active <> 0 AND cg.extends IN ({$custom_extends}) AND cg.is_active <> 0\n ORDER BY cf.custom_group_id, cf.weight";
$dao =& CRM_Core_DAO::executeQuery($sql);
while ($dao
->fetch()) {
if (isset($custom_types[$dao->html_type])) {
$set = 'cg' . $dao->custom_group_id;
if ($dao->entity_type == 'address' || $dao->entity_type == 'relationship') {
$set = $dao->entity_type;
}
elseif (!isset($sets[$set])) {
$sets[$set]['label'] = $dao->custom_group_name;
if ($dao->entity_type != 'activity' && $dao->entity_type != 'participant' && $dao->entity_type != 'case') {
$sets[$set]['entity_type'] = 'contact';
if ($dao->entity_type != 'contact') {
$sets[$set]['contact_type'] = $dao->entity_type;
}
if ($dao->is_multiple) {
$sets[$set]['max_instances'] = $dao->max_multiple ? $dao->max_multiple : 9;
}
else {
$sets[$set]['max_instances'] = 1;
}
}
else {
$sets[$set]['entity_type'] = $dao->entity_type;
}
if ($dao->sub_types) {
$sets[$set]['sub_types'] = explode($sp, trim($dao->sub_types, $sp));
}
if ($dao->extends_entity_column_id) {
$sets[$set]['extension_of'] = $dao->extends_entity_column_id;
}
}
$id = $set . '_custom_' . $dao->id;
$fields[$id] = $custom_types[$dao->html_type];
$fields[$id]['name'] = $dao->label;
$fields[$id]['mandatory'] = $dao->is_required;
$fields[$id]['extra']['description'] = $dao->help_pre;
$fields[$id]['value'] = str_replace($sp, ',', trim($dao->default_value, $sp));
$fields[$id]['data_type'] = $dao->data_type;
if ($dao->entity_type == 'relationship' && $dao->sub_types) {
$fields[$id]['attributes']['data-relationship-type'] = str_replace($sp, ',', trim($dao->sub_types, $sp));
}
if ($fields[$id]['type'] == 'date') {
$fields[$id]['extra']['start_date'] = ($dao->start_date_years ? '-' . $dao->start_date_years : '-50') . ' years';
$fields[$id]['extra']['end_date'] = ($dao->end_date_years ? '+' . $dao->end_date_years : '+50') . ' years';
// Add "time" component for datetime fields
if (!empty($dao->time_format)) {
$fields[$id]['name'] .= ' - ' . t('date');
$fields[$id . '_timepart'] = array(
'name' => $dao->label . ' - ' . t('time'),
'type' => 'time',
'extra' => array(
'hourformat' => $dao->time_format == 1 ? '12-hour' : '24-hour',
),
);
}
}
elseif ($og = $dao->option_group_id) {
$lists[$set . '_custom_' . $dao->id] = $og;
$fields[$id]['extra']['civicrm_live_options'] = 1;
}
elseif ($dao->html_type == 'Select Country' || $dao->html_type == 'Multi-Select Country') {
$lists[$set . '_custom_' . $dao->id] = 'country';
$fields[$id]['extra']['civicrm_live_options'] = 1;
}
elseif ($dao->html_type == 'Select State/Province' || $dao->html_type == 'Multi-Select State/Province') {
$lists[$set . '_custom_' . $dao->id] = 'state_province';
$fields[$id]['extra']['civicrm_live_options'] = 1;
}
elseif ($fields[$id]['data_type'] == 'ContactReference') {
$lists[$set . '_custom_' . $dao->id] = 'contact';
$fields[$id]['expose_list'] = TRUE;
$fields[$id]['empty_option'] = t('None');
}
elseif ($fields[$id]['type'] == 'select') {
$lists[$set . '_custom_' . $dao->id] = 'yes_no';
}
elseif ($fields[$id]['type'] == 'textarea') {
$fields[$id]['extra']['cols'] = $dao->note_columns;
$fields[$id]['extra']['rows'] = $dao->note_rows;
}
}
}
$dao
->free();
}
return ${$var};
}