You are here

function webform_civicrm_node_load in Webform CiviCRM Integration 7.3

Same name and namespace in other branches
  1. 7.5 webform_civicrm.module \webform_civicrm_node_load()
  2. 7 webform_civicrm.module \webform_civicrm_node_load()
  3. 7.2 webform_civicrm.module \webform_civicrm_node_load()
  4. 7.4 webform_civicrm.module \webform_civicrm_node_load()

Implements hook_node_load().

File

./webform_civicrm.module, line 82
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_node_load($nodes, $types) {
  $db = db_query('SELECT * FROM {webform_civicrm_forms} WHERE nid IN(:nids)', array(
    ':nids' => array_keys($nodes),
  ));
  foreach ($db as $settings) {
    $node =& $nodes[$settings->nid];
    $settings->data = unserialize($settings->data);
    $node->webform_civicrm = (array) $settings;

    // Allow a component widget to be changed
    if (!empty($_GET['type']) && arg(0) == 'node' && arg(1) == $node->nid && arg(3) == 'components') {
      if (!empty($node->webform['components'][arg(4)]) && array_key_exists($_GET['type'], webform_components())) {
        $node->webform['components'][arg(4)]['type'] = $_GET['type'];
        webform_component_defaults($node->webform['components'][arg(4)]);
        if ($_GET['type'] == 'select') {
          module_load_include('inc', 'webform_civicrm', 'webform_civicrm_utils');
          civicrm_initialize();
          $node->webform['components'][arg(4)]['extra']['items'] = wf_crm_field_options($node->webform['components'][arg(4)], 'component_insert', $node->webform_civicrm['data']);
        }
      }
    }
  }
}