You are here

function wf_crm_field_options in Webform CiviCRM Integration 7.3

Same name and namespace in other branches
  1. 7.5 includes/utils.inc \wf_crm_field_options()
  2. 7.4 includes/utils.inc \wf_crm_field_options()

Get options for a specific field

Parameters

$field: Webform component array

$context: Where is this being called from?

$data: Array of crm entity data

Return value

array

9 calls to wf_crm_field_options()
theme_webform_civicrm_components_form in ./webform_civicrm_admin.inc
Theme override for webform components form.
webform_civicrm_node_load in ./webform_civicrm.module
Implements hook_node_load().
webform_civicrm_update_7300 in ./webform_civicrm.install
Note: There are differences in how contact references and relationships work in the 3.x branch. Read the upgrade instructions at http://drupal.org/node/1615380
wf_crm_component_insert in ./webform_civicrm_admin.inc
Add a CiviCRM field to a webform
wf_crm_configure_form_item in ./webform_civicrm_admin.inc
Build a field item for the configure form

... See full list

File

./webform_civicrm_utils.inc, line 179
Webform CiviCRM module's common utility functions.

Code

function wf_crm_field_options($field, $context, $data) {
  $ret = array();
  $fields = wf_crm_get_fields();
  if ($pieces = wf_crm_explode_key($field['form_key'])) {
    list(, $c, $ent, $n, $table, $name) = $pieces;

    // Ensure we have complete info for this field
    $field += $fields[$table . '_' . $name];
    if ($name === 'contact_sub_type') {
      list($contact_types, $sub_types) = wf_crm_get_contact_types();
      $ret = $sub_types[$data['contact'][$c]['contact'][1]['contact_type']];
    }
    elseif ($name === 'relationship_type_id') {
      $ret = wf_crm_get_contact_relationship_types($data['contact'][$c]['contact'][1]['contact_type'], $data['contact'][$n]['contact'][1]['contact_type'], $data['contact'][$c]['contact'][1]['contact_sub_type'], $data['contact'][$n]['contact'][1]['contact_sub_type']);
    }
    elseif ($name === 'relationship_permission') {
      $ret = array(
        1 => t('Contact !a may view and edit contact !b', array(
          '!a' => $c,
          '!b' => $n,
        )),
        2 => t('Contact !a may view and edit contact !b', array(
          '!a' => $n,
          '!b' => $c,
        )),
        3 => t('Both contacts may view and edit each other'),
      );
    }
    elseif ($name === 'master_id' || wf_crm_aval($field, 'data_type') === 'ContactReference') {
      $contact_type = wf_crm_get_list($table, $name);
      foreach ($data['contact'] as $num => $contact) {
        if ($num != $c || $name != 'master_id') {
          if ($contact_type == 'contact' || $contact_type == $contact['contact'][1]['contact_type']) {
            $ret[$num] = t('Contact !num', array(
              '!num' => $num,
            ));
          }
        }
      }
    }
    elseif ($name === 'status_id' && $table === 'participant') {
      require_once 'CRM/Event/PseudoConstant.php';
      $ret = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
    }
    elseif ($list = wf_crm_get_list($table, $name)) {
      $param = NULL;
      if ($name === 'event_id') {
        $param = $data['reg_options'] + array(
          'context' => $context,
        );
      }
      elseif ($name === 'survey_id') {
        $param = wf_crm_aval($data, 'activity:1:activity:1');
      }
      if ($list === 'tag') {
        $split = explode('_', $name);
        $param = array(
          'entity' => $ent,
          'tagset' => wf_crm_aval($split, 1),
        );
      }
      $ret = wf_crm_get_options($list, $param);

      // Hack to format money data correctly
      if (!empty($field['data_type']) && $field['data_type'] === 'Money') {
        $old = $ret;
        $ret = array();
        foreach ($old as $key => $val) {
          $ret[number_format(str_replace(',', '', $key), 2, '.', '')] = $val;
        }
      }
    }

    // Remove options that were set behind the scenes on the admin form
    if ($context != 'config_form' && !empty($field['extra']['multiple']) && !empty($field['expose_list'])) {
      foreach (wf_crm_aval($data, "{$ent}:{$c}:{$table}:{$n}:{$name}", array()) as $key => $val) {
        unset($ret[$key]);
      }
    }
  }
  return $context == 'component_insert' ? wf_crm_array2str($ret) : $ret;
}