diff --git a/better_exposed_filters_exposed_form_plugin.inc b/better_exposed_filters_exposed_form_plugin.inc index 6f0140b..e2ee2a2 100644 --- a/better_exposed_filters_exposed_form_plugin.inc +++ b/better_exposed_filters_exposed_form_plugin.inc @@ -133,6 +133,31 @@ Title Desc|Z -> A Leave the replacement value blank to remove an option al '#description' => t('This cannot be left blank if the above option is checked'), '#dependency' => array('edit-exposed-form-options-bef-sort-advanced-reset' => array(1)), ); + + // Dropdown for numeric fields + if ($bef_numeric) { + $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); + $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); + $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); + $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); + $description .= '
' . t('Requires the List module from Core.'); + $description .= '

'; + + $bef_options[$label]['more_options']['bef_numeric_list_0'] = array( + '#type' => 'textarea', + '#title' => t('Dropdown options (first)'), + '#default_value' => $existing[$label]['more_options']['bef_numeric_list_0'], + '#description' => $description, + ); + if (in_array($filter->operator, array('between', 'not between'))) { + $bef_options[$label]['more_options']['bef_numeric_list_1'] = array( + '#type' => 'textarea', + '#title' => t('Dropdown options (second)'), + '#default_value' => $existing[$label]['more_options']['bef_numeric_list_1'], + '#description' => $description, + ); + } + } } /* @@ -228,6 +253,17 @@ Title Desc|Z -> A Leave the replacement value blank to remove an option al // others? $bef_specific = TRUE; } + else if ($bef_numeric = ('views_handler_filter_numeric' == $filter->definition['handler'])) { + $bef_options[$label]['bef_format'] = array( + '#type' => 'select', + '#title' => t('Display "@label" exposed filter as', array('@label' => $filter->options['expose']['label'])), + '#default_value' => $existing[$label]['bef_format'], + '#options' => array( + 'default' => t('Default numeric field'), + 'bef_dropdown' => t('Dropdown with preset values'), + ), + ); + } else { // dsm($filter->definition['type']); } @@ -834,6 +870,30 @@ Title Desc|Z -> A Leave the replacement value blank to remove an option al } break; + case 'bef_dropdown': + if (!module_exists('list')) { + break; + } + $formfield = array( + '#type' => 'select', + '#options' => list_extract_allowed_values($options['more_options']['bef_numeric_list_0'], 'list_float', TRUE), + '#multiple' => FALSE, + '#size' => 0, + ); + + if (isset($form[$field_id]['#tree'])) { + $form[$field_id]['min'] = array_merge($form[$field_id]['min'], $formfield); + + $form[$field_id]['max']['#type'] = 'select'; + $form[$field_id]['max']['#options'] = list_extract_allowed_values($options['more_options']['bef_numeric_list_1'], 'list_float', TRUE); + $form[$field_id]['max']['#multiple'] = FALSE; + $form[$field_id]['max']['#size'] = 0; + } + else { + $form[$field_id] = array_merge($form[$field_id], $formfield); + } + break; + default: // Handle functionality for exposed filters that are not limited to BEF only filters $show_apply = TRUE;