You are here

function webform_load in Webform 5

Same name and namespace in other branches
  1. 5.2 webform.module \webform_load()
  2. 6.2 webform.module \webform_load()

Implemenation of hook_load().

File

./webform.module, line 262

Code

function webform_load($node) {
  $additions = db_fetch_object(db_query("SELECT * FROM {webform} WHERE nid = %d", $node->nid));
  $additions->webformcomponents = array();
  $result = db_query('SELECT * FROM {webform_component} WHERE nid = %d ORDER BY weight, name', $node->nid);
  while ($c = db_fetch_array($result)) {
    $additions->webformcomponents[$c['cid']]['cid'] = $c['cid'];
    $additions->webformcomponents[$c['cid']]['nid'] = $c['nid'];
    $additions->webformcomponents[$c['cid']]['form_key'] = $c['form_key'] ? $c['form_key'] : $c['cid'];
    $additions->webformcomponents[$c['cid']]['name'] = t($c['name']);
    $additions->webformcomponents[$c['cid']]['type'] = $c['type'];
    $additions->webformcomponents[$c['cid']]['value'] = $c['value'];
    $additions->webformcomponents[$c['cid']]['extra'] = unserialize($c['extra']);
    $additions->webformcomponents[$c['cid']]['mandatory'] = $c['mandatory'];
    $additions->webformcomponents[$c['cid']]['parent'] = $c['pid'];
    $additions->webformcomponents[$c['cid']]['weight'] = $c['weight'];
  }

  // Organize the components into a fieldset-based order.
  if (!empty($additions->webformcomponents)) {
    $component_tree = array();
    $page_count = 1;
    _webform_components_tree_build($additions->webformcomponents, $component_tree, 0, $page_count);
    $additions->webformcomponents = _webform_components_tree_flatten($component_tree['children']);
  }
  return $additions;
}