function wf_crm_process_form_settings in Webform CiviCRM Integration 7.3
Build the $data array for webform settings; called while rebuilding or post-processing the configure form.
Parameters
$vals: form_state[values] reference
2 calls to wf_crm_process_form_settings()
- 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_admin.inc, line 604
Code
function wf_crm_process_form_settings(&$vals) {
$data = array(
'contact' => array(),
);
list($contact_types, $sub_types) = wf_crm_get_contact_types();
for ($c = 1; $c <= $vals['number_of_contacts']; ++$c) {
// Contact settings
if (isset($vals[$c . '_contact_type'])) {
$data['contact'][$c] = array(
'contact' => array(
1 => array(
'contact_type' => $vals[$c . '_contact_type'],
'contact_sub_type' => array(),
),
),
);
if ($sub_type = wf_crm_aval($vals, 'civicrm_' . $c . '_contact_1_contact_contact_sub_type')) {
$allowed = $sub_types[$vals[$c . '_contact_type']];
foreach ($sub_type as $sub) {
if (isset($allowed[$sub])) {
$data['contact'][$c]['contact'][1]['contact_sub_type'][$sub] = $sub;
}
}
}
}
else {
$data['contact'][$c] = array(
'contact' => array(
1 => array(
'contact_type' => 'individual',
'contact_sub_type' => array(),
),
),
);
// Set defaults for new contact
$vals += array(
'civicrm_' . $c . '_contact_1_contact_first_name' => 'create_civicrm_webform_element',
'civicrm_' . $c . '_contact_1_contact_last_name' => 'create_civicrm_webform_element',
);
// Add as activity target
if (isset($vals['activity_subject'])) {
$vals['civicrm_1_activity_1_activity_target_contact_id']["{$c}"] = "{$c}";
}
drupal_set_message(t('Tip: Consider using the clone feature to add multiple similar contacts. (see help for more info)'), 'status', FALSE);
}
}
// Store "number of foo for bar" fields, i.e. number of email for contact 1
foreach ($vals as $key => $val) {
if (strpos($key, '_number_of_') !== FALSE) {
list($ent, $c, $k) = explode('_', $key, 3);
if (isset($data[$ent][$c]) || $ent == 'participant') {
$data[$ent][$c][$k] = $val;
}
}
}
if (!empty($vals['activity_type_id'])) {
$data['activity'][1]['activity'][1]['activity_type_id'] = $vals['activity_type_id'];
if (isset($vals['activity_subject'])) {
$data['activity'][1]['activity'][1]['subject'] = $vals['activity_subject'];
$data['activity'][1]['details'] = $vals['activity_details'];
$data['activity'][1]['existing_activity_status'] = $vals['existing_activity_status'];
}
else {
$data['activity'][1]['activity'][1]['target_contact_id'] = range(1, $vals['number_of_contacts']);
}
}
if (!empty($vals['civicrm_1_activity_1_activity_campaign_id'])) {
$data['activity'][1]['activity'][1]['activity_campaign_id'] = $vals['civicrm_1_activity_1_activity_campaign_id'];
}
if (!empty($vals['civicrm_1_activity_1_activity_survey_id'])) {
$data['activity'][1]['activity'][1]['activity_survey_id'] = $vals['civicrm_1_activity_1_activity_survey_id'];
}
if (!empty($vals['case_type_id'])) {
if (empty($data['case'][1])) {
$data['case'][1]['case'][1]['creator_id'] = 1;
}
$data['case'][1]['case'][1]['case_type_id'] = $vals['case_type_id'];
$data['case'][1]['existing_case_status'] = $vals['existing_case_status'];
}
if (isset($vals['participant_reg_type'])) {
$data['participant_reg_type'] = $vals['participant_reg_type'];
$data['reg_options'] = $vals['reg_options'];
}
$vals['data'] = $data;
}