You are here

function vefl_plugin_exposed_form_basic::options_form in Views exposed form layout 7

Provide a form for setting options.

Overrides views_plugin_exposed_form::options_form

File

views/vefl_plugin_exposed_form_basic.inc, line 29
Provides plugin to output Views exposed filters in layout for basic.

Class

vefl_plugin_exposed_form_basic
Exposed form plugin that provides a basic exposed form with layout options.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $layouts = vefl_get_layouts();
  $layout_id = $this->options['layout']['layout_id'];

  // Prepare layout select options.
  $options = array();
  foreach ($layouts as $name => $layout) {
    $module = !empty($layout['module']) ? $layout['module'] : 'VEFL';
    $options[$module][$name] = $layout['title'];
  }

  // Remove module categories if only one category.
  if (count($options) < 2) {
    $options = reset($options);
  }

  // Outputs layout selectbox.
  $form['layout'] = array(
    '#type' => 'fieldset',
    '#title' => t('Layout settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['layout']['layout_id'] = array(
    '#prefix' => '<div class="container-inline">',
    '#type' => 'select',
    '#options' => $options,
    '#title' => t('Layout'),
    '#default_value' => $layout_id,
  );
  $form['layout']['change'] = array(
    '#type' => 'submit',
    '#value' => t('Change'),
    '#submit' => array(
      '_vefl_change_layout_button',
    ),
    '#suffix' => '</div>',
  );

  // Outputs regions selectbox for each filter.
  $types = array(
    'filters' => $this->display->handler
      ->get_handlers('filter'),
    'actions' => vefl_form_actions(),
  );
  $regions = $layouts[$layout_id]['regions'];
  foreach ($types as $type => $fields) {
    foreach ($fields as $id => $filter) {
      if ($type == 'filters') {
        if (!$filter->options['exposed']) {
          continue;
        }
        $filter = $filter->definition['title'];
      }
      $form['layout']['widget_region'][$id] = array(
        '#type' => 'select',
        '#title' => $filter,
        '#options' => $regions,
      );

      // Set default region for chosen layout.
      if (!empty($this->options['layout']['widget_region'][$id]) && !empty($regions[$this->options['layout']['widget_region'][$id]])) {
        $form['layout']['widget_region'][$id]['#default_value'] = $this->options['layout']['widget_region'][$id];
      }
    }
  }

  // Store regions in form_state to have it in options array.
  $form_state['layout_regions'] = $regions;
}