function wf_crm_contact_clone in Webform CiviCRM Integration 7.5
Same name and namespace in other branches
- 8.5 webform_civicrm.module \wf_crm_contact_clone()
- 7.3 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_admin_component::alterForm in includes/
wf_crm_admin_component.inc - Alter back-end webform component edit forms. Called by hook_form_alter() whenever editing a webform component.
File
- ./
webform_civicrm.module, line 666 - 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) {
form_load_include($form_state, 'inc', 'webform_civicrm', 'includes/utils');
$fid = $form['form_key']['#default_value'];
list(, $old) = 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];
// Set label
$settings['data']['contact'][$new]['contact'][1]['webform_label'] = $form_state['input']['name'];
$storage = [
'old' => [
"civicrm_{$old}_contact_",
],
'new' => [
"civicrm_{$new}_contact_",
],
];
// Clone participant 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);
}