You are here

function webform_civicrm_contact_clone in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm.module \webform_civicrm_contact_clone()

Clone a contact via webform. This submit handler is called when cloning a contact's fieldset

1 string reference to 'webform_civicrm_contact_clone'
_webform_civicrm_webform_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 369
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_contact_clone($form, $form_state) {
  module_load_include('inc', 'webform_civicrm', 'webform_civicrm_utils');
  $fid = $form['form_key']['#default_value'];
  list($lobo, $old, $ent, $n, $table, $key) = webform_civicrm_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 (webform_civicrm_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
  webform_civicrm_contact_clone_storage($storage);
}