function wf_crm_contact_clone in Webform CiviCRM Integration 7.3
Same name and namespace in other branches
- 8.5 webform_civicrm.module \wf_crm_contact_clone()
- 7.5 webform_civicrm.module \wf_crm_contact_clone()
- 7.4 webform_civicrm.module \wf_crm_contact_clone()
Clone a contact via webform. This submit handler is called when cloning a contact's fieldset
1 string reference to 'wf_crm_contact_clone'
- _wf_crm_component_form_alter in ./
webform_civicrm_admin.inc - Alter back-end webform component edit forms. Called by hook_form_alter() whenever editing a webform component.
File
- ./
webform_civicrm.module, line 454 - Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts
Code
function wf_crm_contact_clone($form, $form_state) {
module_load_include('inc', 'webform_civicrm', 'webform_civicrm_utils');
$fid = $form['form_key']['#default_value'];
list(, $old, $ent, $n, $table, $key) = wf_crm_explode_key($fid);
$node = node_load($form['nid']['#value']);
$settings = $node->webform_civicrm;
$new = count($settings['data']['contact']) + 1;
// Clone contact
$settings['data']['contact'][$new] = $settings['data']['contact'][$old];
$storage = array(
'old' => array(
"civicrm_{$old}_contact_",
),
'new' => array(
"civicrm_{$new}_contact_",
),
);
// Clone particpant if registering separately
if (wf_crm_aval($settings['data'], 'participant_reg_type') == 'separate') {
$settings['data']['participant'][$new] = $settings['data']['participant'][$old];
$storage['old'][] = "civicrm_{$old}_participant_";
$storage['new'][] = "civicrm_{$new}_participant_";
}
drupal_write_record('webform_civicrm_forms', $settings, 'nid');
// Store data to rewrite form keys
wf_crm_contact_clone_storage($storage);
}