You are here

function views_dependent_filters_handler_filter_dependent::options_form in Views Dependent Filters 7

Provide the basic form which calls through to subforms. If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called.

Overrides views_handler_filter::options_form

File

./views_dependent_filters_handler_filter_dependent.inc, line 113

Class

views_dependent_filters_handler_filter_dependent

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);

  // Lock the exposed checkbox.
  $form['expose_button']['checkbox']['checkbox']['#disabled'] = TRUE;
  $form['expose_button']['checkbox']['checkbox']['#description'] = t('This filter is always exposed.');

  // Not sure what the 'expose' button is for as there's the checkbox, but
  // it's not wanted here.
  unset($form['expose_button']['markup']);
  unset($form['expose_button']['button']);
  $filters = $this->view->display_handler->handlers['filter'];
  if (isset($this->options['controller_filter'])) {

    // Get the handler for the controller filter.
    $controller_filter = $filters[$this->options['controller_filter']];

    // Take copies of the form arrays to pass to the other handler.
    $form_copy = $form;
    $form_state_copy = $form_state;

    // Fixup the form so the handler is fooled.
    // For some reason we need to add this for non-ajax admin operation.
    $form_copy['operator']['#type'] = '';

    // Get the value form from the filter handler.
    $controller_filter
      ->value_form($form_copy, $form_state);
    $controller_values_element = $form_copy['value'];

    // Clean up the form element.
    if ($controller_values_element['#type'] == 'checkboxes') {

      // We have to unset the 'select all' option on checkboxes.
      unset($controller_values_element['#options']['all']);

      // Force multiple.
      $controller_values_element['#multiple'] = TRUE;
    }

    // Add it to our own form element in the real form.
    $form['controller_values'] = array(
      '#title' => t('Controller values'),
      '#description' => t('The values on the controller filter that will cause the dependent filters to be visible.'),
      '#default_value' => isset($this->options['controller_values']) ? $this->options['controller_values'] : array(),
    ) + $controller_values_element;
  }
  $options = $this
    ->get_filter_options('dependent');
  $form['dependent_filters'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Dependent filters'),
    '#options' => $options,
    '#default_value' => isset($this->options['dependent_filters']) ? $this->options['dependent_filters'] : array(),
    '#description' => t('The filters which should only be visible and active when the controller filter has the given values.'),
  );
  if (empty($options)) {
    $form['dependent_filters']['#description'] .= ' ' . t('This filter needs other filters to be placed below it in the order to use as dependents.');
  }
}