function wf_crm_field_options in Webform CiviCRM Integration 7.4
Same name and namespace in other branches
- 7.5 includes/utils.inc \wf_crm_field_options()
- 7.3 webform_civicrm_utils.inc \wf_crm_field_options()
Get options for a specific field
Parameters
array $field: Webform component array
string $context: Where is this being called from?
array $data: Array of crm entity data
Return value
array
11 calls to wf_crm_field_options()
- 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_admin_component::buildOptionsTable in includes/
wf_crm_admin_component.inc - Interface similar to options_element module but with the important difference that options already exist in the civi db so this does not allow create/delete of options
- wf_crm_admin_component::postProcess in includes/
wf_crm_admin_component.inc - Custom Processing for CiviCRM webform component option lists
- wf_crm_admin_component::preprocessComponentsForm in includes/
wf_crm_admin_component.inc - Add CiviCRM info and theming to webform components form.
File
- includes/
utils.inc, line 20 - 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
if (isset($fields[$table . '_' . $name])) {
$field += $fields[$table . '_' . $name];
}
if ($name === 'contact_sub_type') {
list($contact_types, $sub_types) = wf_crm_get_contact_types();
$ret = wf_crm_aval($sub_types, $data['contact'][$c]['contact'][1]['contact_type'], array());
}
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('!a may view and edit !b', array(
'!a' => wf_crm_contact_label($c, $data, 'plain'),
'!b' => wf_crm_contact_label($n, $data, 'plain'),
)),
2 => t('!a may view and edit !b', array(
'!a' => wf_crm_contact_label($n, $data, 'plain'),
'!b' => wf_crm_contact_label($c, $data, 'plain'),
)),
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_aval($field, 'reference_contact_type', 'contact');
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] = wf_crm_contact_label($num, $data, 'plain');
}
}
}
}
elseif ($name == 'privacy') {
$ret = wf_crm_get_privacy_options();
}
elseif ($table === 'other') {
if ($field['table'] === 'tag') {
$split = explode('_', $name);
$ret = CRM_Core_BAO_Tag::getTags("civicrm_{$ent}", $ret, wf_crm_aval($split, 1), '- ');
}
elseif ($field['table'] === 'group') {
$ret = wf_crm_apivalues('group', 'get', array(
'is_hidden' => 0,
), 'title');
}
}
elseif ($name === 'survey_id') {
$ret = wf_crm_get_surveys(wf_crm_aval($data, "activity:{$c}:activity:1", array()));
}
elseif ($name == 'event_id') {
$ret = wf_crm_get_events($data['reg_options'], $context);
}
elseif ($table == 'contribution' && $name == 'is_test') {
// Getoptions would return 'yes' and 'no' - this is a bit more descriptive
$ret = array(
0 => t('Live Transactions'),
1 => t('Test Mode'),
);
}
elseif ($table == 'membership' && $name == 'num_terms') {
$ret = drupal_map_assoc(range(1, 9));
}
else {
$params = array(
'field' => $name,
'context' => 'create',
);
// Special case for contribution_recur fields
if ($table == 'contribution' && strpos($name, 'frequency_') === 0) {
$table = 'contribution_recur';
}
// Use the Contribution table to pull up financial type id-s
if ($table == 'membership' && $name == 'financial_type_id') {
$table = 'contribution';
}
// Custom fields - use main entity
if (substr($table, 0, 2) == 'cg') {
$table = $ent;
}
else {
// Pass data into api.getoptions for contextual filtering
$params += wf_crm_aval($data, "{$ent}:{$c}:{$table}:{$n}", array());
}
$ret = wf_crm_apivalues($table, 'getoptions', $params);
// 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]);
}
}
}
if (!empty($field['exposed_empty_option'])) {
$ret = array(
0 => $field['exposed_empty_option'],
) + $ret;
}
return $ret;
}