You are here

function cck_select_other_handler_filter::exposed_form in CCK Select Other 7.2

Same name and namespace in other branches
  1. 7 views/cck_select_other_handler_filter.inc \cck_select_other_handler_filter::exposed_form()

Exposed form

Overrides views_handler_filter::exposed_form

File

views/cck_select_other_handler_filter.inc, line 24

Class

cck_select_other_handler_filter
Extends Views in operator filter.

Code

function exposed_form(&$form, &$form_state) {
  parent::exposed_form($form, $form_state);
  $identifier = $this->options['expose']['identifier'];

  // Populate other default value if any.
  $otherdef = '';
  $other_values = array_diff($this->value, $this->value_options);
  if (!empty($other_values)) {
    $otherdef = array_pop($other_values);
    $form[$identifier]['select_other_list']['#default_value'][] = 'other';
  }
  $form[$identifier]['select_other_text_input'] = array(
    '#type' => 'textfield',
    '#title' => t('Other'),
    '#title_display' => 'invisible',
    '#attributes' => array(
      'class' => array(
        'form-text select_other_text_input',
      ),
    ),
    '#default_value' => $otherdef,
    '#parents' => array(
      'options',
      'value',
      'select_other_text_input',
    ),
    '#size' => 10,
  );
  $form[$identifier]['#parents'] = array(
    'options',
    $identifier,
  );
  $form[$identifier]['select_other_list']['#type'] = 'select';
  $form[$identifier]['select_other_list']['#multiple'] = $this->options['expose']['multiple'];
  $form[$identifier]['select_other_list']['#parents'] = array(
    'options',
    $identifier,
    'select_other_list',
  );
  $form[$identifier]['select_other_text_input']['#parents'] = array(
    'options',
    $identifier,
    'select_other_text_input',
  );
  if (empty($form_state['exposed']) || empty($this->options['expose']['required'])) {

    // If we're configuring an exposed filter, add an <Any> option.
    $any_label = variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? '<Any>' : t('- Any -');
    $form[$identifier]['select_other_list']['#options'] = array(
      'All' => $any_label,
    ) + $form[$identifier]['select_other_list']['#options'];
  }
  $field_id = str_replace('_', '-', 'options-' . $identifier);
  drupal_add_js(array(
    'CCKSelectOther' => array(
      array(
        'field_id' => $field_id,
      ),
    ),
  ), array(
    'type' => 'setting',
  ));
}