function webform_civicrm_get_fields in Webform CiviCRM Integration 7
Same name and namespace in other branches
- 6.2 webform_civicrm_utils.inc \webform_civicrm_get_fields()
- 6 webform_civicrm_utils.inc \webform_civicrm_get_fields()
- 7.2 webform_civicrm_utils.inc \webform_civicrm_get_fields()
Fetches CiviCRM field data @Param $var: name of variable to return: fields, tokens or lists @Return fields: The CiviCRM contact fields this module supports @Return tokens: Available tokens keyed to field ids @Return lists: Option lists keyed to option_group name
8 calls to webform_civicrm_get_fields()
- webform_civicrm_configure_form in ./
webform_civicrm_forms.inc - Form to configure CiviCRM options for a Webform
- webform_civicrm_configure_form_submit in ./
webform_civicrm_forms.inc - Submission handler, saves CiviCRM options for a Webform node
- webform_civicrm_contact_match in ./
webform_civicrm_utils.inc - Create or update CiviCRM contact Called by both presave and insert webform hooks in order to handle the optional contact_id field correctly
- webform_civicrm_enabled_fields in ./
webform_civicrm_utils.inc - Get ids of enabled CiviCRM fields for a webform @Param $node - node object
- webform_civicrm_js_options in ./
webform_civicrm_utils.inc - Return CiviCRM options via AJAX request
File
- ./
webform_civicrm_utils.inc, line 365 - Webform CiviCRM module's utility functions.
Code
function webform_civicrm_get_fields($var = 'fields') {
static $fields = 0;
static $tokens = 0;
static $lists = 0;
if (!$fields) {
// The order of these fields is important: see function webform_civicrm_contact_match
$fields = array();
// Contact params
$fields['civicrm_first_name'] = array(
'name' => t('First Name'),
'type' => 'textfield',
'mandatory' => 1,
);
$fields['civicrm_nick_name'] = array(
'name' => t('Nick Name'),
'type' => 'textfield',
);
$fields['civicrm_middle_name'] = array(
'name' => t('Middle Name'),
'type' => 'textfield',
);
$fields['civicrm_last_name'] = array(
'name' => t('Last Name'),
'type' => 'textfield',
'mandatory' => 1,
);
$fields['civicrm_prefix_id'] = array(
'name' => t('Name Prefix'),
'type' => 'select',
);
$fields['civicrm_suffix_id'] = array(
'name' => t('Name Suffix'),
'type' => 'select',
);
$fields['civicrm_gender_id'] = array(
'name' => t('Gender'),
'type' => 'select',
);
$fields['civicrm_birth_date'] = array(
'name' => t('Birth Date'),
'type' => 'date',
'extra' => array(
'year_start' => '-100',
'year_end' => '-1',
'timezone' => 'user',
),
);
$fields['civicrm_job_title'] = array(
'name' => t('Job Title'),
'type' => 'textfield',
);
$fields['civicrm_contact_id'] = array(
'name' => t('Contact ID'),
'type' => 'hidden',
'extra' => array(
'description' => t('(hidden field, useful for post-processing)'),
),
);
$fields['civicrm_external_identifier'] = array(
'name' => t('External ID'),
'type' => 'hidden',
'extra' => array(
'description' => t('(hidden field, useful for post-processing)'),
),
);
$fields['civicrm_preferred_communication_method'] = array(
'name' => t('Preferred Communication Method(s)'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
),
);
// Email params -- email must be first!
$fields['civicrm_email'] = array(
'name' => t('Email'),
'type' => 'email',
'mandatory' => 1,
);
// Address params -- street_address must be first!
$fields['civicrm_street_address'] = array(
'name' => t('Street Address'),
'type' => 'textfield',
'extra' => array(
'width' => 60,
),
);
$fields['civicrm_supplemental_address_1'] = array(
'name' => t('Street Address Line 2'),
'type' => 'textfield',
'extra' => array(
'width' => 60,
),
);
$fields['civicrm_supplemental_address_2'] = array(
'name' => t('Street Address Line 3'),
'type' => 'textfield',
'extra' => array(
'width' => 60,
),
);
$fields['civicrm_city'] = array(
'name' => t('City'),
'type' => 'textfield',
);
$fields['civicrm_state_province'] = array(
'name' => t('State/Province Abbr.'),
'type' => 'textfield',
'extra' => array(
'maxlength' => 4,
'width' => 4,
'description' => t('Enter state/province abbreviation'),
),
);
$fields['civicrm_state_province_id'] = array(
'name' => t('State/Province Select'),
'type' => 'select',
'extra' => array(
'description' => t('Select state/province from list'),
),
);
$fields['civicrm_postal_code'] = array(
'name' => t('Postal Code'),
'type' => 'textfield',
'extra' => array(
'width' => 10,
),
);
$fields['civicrm_country_id'] = array(
'name' => t('Country'),
'type' => 'select',
);
// Phone params -- phone must be first!
$fields['civicrm_phone'] = array(
'name' => t('Phone Number'),
'type' => 'textfield',
);
$fields['civicrm_phone_type_id'] = array(
'name' => t('Phone Type'),
'type' => 'select',
);
// Other
$fields['civicrm_groups'] = array(
'name' => t('Select Group(s)'),
'type' => 'select',
'extra' => array(
'multiple' => 1,
'description' => t('Users can add/remove themselves from CiviCRM groups (mailing lists, etc)'),
),
);
$fields['civicrm_groups_hidden'] = array(
'name' => t('Auto-Add Group(s)'),
'type' => 'hidden',
'extra' => array(
'description' => t('Hidden form element will add contacts to group(s) of your choosing'),
),
);
$fields['civicrm_tags'] = array(
'name' => t('Tags'),
'type' => 'hidden',
'extra' => array(
'description' => t('Hidden form element to add tags to contacts'),
),
);
$tokens = array(
'display_name' => t('display name'),
'first_name' => t('first name'),
'nick_name' => t('nick name'),
'middle_name' => t('middle name'),
'last_name' => t('last name'),
'prefix' => t('name prefix'),
'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'),
);
$lists = array(
'civicrm_phone_type_id' => 'phone_type',
'civicrm_prefix_id' => 'individual_prefix',
'civicrm_suffix_id' => 'individual_suffix',
'civicrm_gender_id' => 'gender',
'civicrm_country_id' => 'country',
'civicrm_state_province_id' => 'state',
'civicrm_preferred_communication_method' => 'preferred_communication_method',
);
// 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,
'aslist' => 0,
),
),
'Text' => array(
'type' => 'textfield',
),
'TextArea' => array(
'type' => 'textarea',
),
'RichTextArea' => array(
'type' => '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,
),
),
);
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
$sql = "\n SELECT cf.*, cg.title as custom_group_name 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 ('Individual','Contact') AND cg.is_active <> 0\n ORDER BY cf.custom_group_id, cf.weight";
$dao =& CRM_Core_DAO::executeQuery($sql);
while ($dao
->fetch()) {
if (!$custom_types[$dao->html_type]) {
continue;
}
$id = 'civicrm_custom_' . $dao->id;
$label = drupal_strtolower($dao->label);
// Prevent token namespace collisions
if (in_array($label, $tokens)) {
$label .= ' ' . $dao->id;
}
$tokens['custom_' . $dao->id] = $label;
$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]['custom_group'] = $dao->custom_group_name;
if ($fields[$id]['type'] == 'date') {
$fields[$id]['extra']['year_start'] = $dao->start_date_years ? '-' . $dao->start_date_years : '-50';
$fields[$id]['extra']['year_end'] = $dao->end_date_years ? '+' . $dao->end_date_years : '+50';
}
elseif ($og = $dao->option_group_id) {
$lists[$id] = $og;
}
elseif ($dao->html_type == 'Select Country' || $dao->html_type == 'Multi-Select Country') {
$lists[$id] = 'country';
}
elseif ($dao->html_type == 'Select State/Province' || $dao->html_type == 'Multi-Select State/Province') {
$lists[$id] = 'state';
}
elseif ($fields[$id]['type'] == 'select') {
$fields[$id]['extra']['items'] = '1|' . t('Yes') . "\n0|" . t('No');
}
elseif ($fields[$id]['type'] == 'textarea') {
$fields[$id]['extra']['cols'] = $dao->note_columns;
$fields[$id]['extra']['rows'] = $dao->note_rows;
}
}
}
return ${$var};
}