You are here

function webform_civicrm_node_load in Webform CiviCRM Integration 7.5

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

Implements hook_node_load().

Parameters

array $nodes:

File

./webform_civicrm.module, line 138
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)', [
    ':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', 'includes/utils');
          civicrm_initialize();
          $node->webform['components'][arg(4)]['extra']['items'] = wf_crm_array2str(wf_crm_field_options($node->webform['components'][arg(4)], 'component_insert', $node->webform_civicrm['data']));
        }
      }
    }
  }
}