You are here

public function wf_crm_admin_component::postProcess in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/wf_crm_admin_component.inc \wf_crm_admin_component::postProcess()

Custom Processing for CiviCRM webform component option lists

File

includes/wf_crm_admin_component.inc, line 394

Class

wf_crm_admin_component

Code

public function postProcess() {
  $vals =& $this->form_state['values'];
  $vals['value'] = '';
  foreach ($vals['civicrm_options_fieldset']['civicrm_defaults'] as $k) {
    if ($k) {
      $vals['value'] .= ($vals['value'] ? ',' : '') . str_replace('_web_civi_option_selected_', '', $k);
    }
  }
  if (isset($vals['civicrm_options_fieldset']['civicrm_options'])) {
    if (empty($vals['extra']['civicrm_live_options'])) {
      $items = array();
      foreach ($vals['civicrm_options_fieldset']['civicrm_options'] as $k) {
        if ($k) {
          $v = str_replace('_web_civi_option_selected_', '', $k);
          if (!($label = $vals['civicrm_options_fieldset']['civicrm_option_label_' . $v])) {
            $label = $this->form['civicrm_options_fieldset']['civicrm_option_name_' . $v]['#value'];
          }
          $items[$vals['civicrm_options_fieldset']['civicrm_option_weight_' . $v]] = $v . '|' . $label;
        }
      }
      ksort($items);
      $vals['extra']['items'] = implode("\n", $items);

      // A single static radio should be shown as a checkbox
      if (count($items) == 1 && empty($vals['extra']['aslist'])) {
        $vals['extra']['multiple'] = 1;
      }
    }
    else {
      $items = wf_crm_field_options($vals, 'live_options', $this->data);
      $items += wf_crm_str2array($vals['extra']['items']);
      $vals['extra']['items'] = wf_crm_array2str($items);
    }
  }
}