You are here

class vefl_plugin_exposed_form_basic in Views exposed form layout 7

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

Hierarchy

Expanded class hierarchy of vefl_plugin_exposed_form_basic

1 string reference to 'vefl_plugin_exposed_form_basic'
vefl_views_plugins in views/vefl.views.inc
Implements hook_views_plugins().

File

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

View source
class vefl_plugin_exposed_form_basic extends views_plugin_exposed_form_basic {
  function option_definition() {
    $options = parent::option_definition();
    $options['layout'] = array(
      'contains' => array(
        'layout_id' => array(
          'default' => 'vefl_onecol',
        ),
        'regions' => array(
          'default' => array(),
        ),
        'widget_region' => array(
          'default' => array(),
        ),
      ),
    );
    return $options;
  }

  /**
   * Provide a form for setting options.
   */
  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;
  }

  /**
   * Submit handler for the options to rebuild theme registry.
   */
  function options_submit(&$form, &$form_state) {
    parent::options_submit($form, $form_state);
    $form_state['values']['exposed_form_options']['layout']['regions'] = $form_state['layout_regions'];
    drupal_theme_rebuild();
  }

  /**
   * Views exposed form alter function.
   *
   * Changes form's theme function if needed and
   * adds '#layout' attribute with layout settings.
   */
  function exposed_form_alter(&$form, &$form_state) {
    parent::exposed_form_alter($form, $form_state);
    $view =& $form_state['view'];
    $display =& $form_state['display'];
    $layout_id = $this->options['layout']['layout_id'];

    // Fill regions.
    $region_widgets = array();
    $regions = array_keys(array_filter($this->options['layout']['regions']));
    foreach ($regions as $region) {
      $region_widgets[$region] = array();
    }

    // Shorthand for all filters in this view.
    $filters = $form_state['view']->display_handler->handlers['filter'];
    foreach ($this->display->handler
      ->get_handlers('filter') as $label => $filter) {
      if (!$filter->options['exposed']) {
        continue;
      }
      $filter_region = !empty($this->options['layout']['widget_region'][$label]) ? $this->options['layout']['widget_region'][$label] : reset($regions);
      $filter_key = 'filter-' . ($filters[$label]->options['is_grouped'] ? $filters[$label]->options['group_info']['identifier'] : $label);
      $region_widgets[$filter_region][] = $filter_key;
    }

    // Fill action fields.
    $actions = array_keys(vefl_form_actions());
    foreach ($actions as $action_id) {
      $filter_region = $this->options['layout']['widget_region'][$action_id];
      $region_widgets[$filter_region][] = $action_id;
    }
    $form['#theme'] = _vefl_form_theme_functions($layout_id, $view, $display);
    $form['#layout'] = $this->options['layout'];
    $form['#layout']['region_widgets'] = $region_widgets;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
vefl_plugin_exposed_form_basic::exposed_form_alter function Views exposed form alter function. Overrides views_plugin_exposed_form::exposed_form_alter
vefl_plugin_exposed_form_basic::options_form function Provide a form for setting options. Overrides views_plugin_exposed_form::options_form
vefl_plugin_exposed_form_basic::options_submit function Submit handler for the options to rebuild theme registry. Overrides views_plugin::options_submit
vefl_plugin_exposed_form_basic::option_definition function Information about options for all kinds of purposes will be held here. Overrides views_plugin_exposed_form::option_definition
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::options_validate public function Validate the options form. 10
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_exposed_form::exposed_form_submit public function This function is executed when exposed form is submited.
views_plugin_exposed_form::exposed_form_validate public function
views_plugin_exposed_form::init public function Initialize the plugin.
views_plugin_exposed_form::post_execute public function
views_plugin_exposed_form::post_render public function
views_plugin_exposed_form::pre_execute public function
views_plugin_exposed_form::pre_render public function 1
views_plugin_exposed_form::query public function Add anything to the query that we might need to. Overrides views_plugin::query 1
views_plugin_exposed_form::render_exposed_form public function Render the exposed filter form.
views_plugin_exposed_form::reset_form public function