You are here

class views_ef_fieldset_display_extender_plugin in Views Exposed Form Fieldset 7

Same name and namespace in other branches
  1. 7.2 views/views_ef_fieldset_display_extender_plugin.inc \views_ef_fieldset_display_extender_plugin

@file Provides a display extender plugin for View 3.x.

Hierarchy

Expanded class hierarchy of views_ef_fieldset_display_extender_plugin

1 string reference to 'views_ef_fieldset_display_extender_plugin'
views_ef_fieldset_views_plugins in ./views_ef_fieldset.views.inc
Implements hook_views_plugins().

File

views/views_ef_fieldset_display_extender_plugin.inc, line 7
Provides a display extender plugin for View 3.x.

View source
class views_ef_fieldset_display_extender_plugin extends views_plugin_display_extender {
  function options_definition_alter(&$options) {
    parent::options_definition_alter($options);
    $options['views_ef_fieldset'] = array(
      'contains' => array(
        'enabled' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'options' => array(),
      ),
    );
  }

  /**
   * Provide a form to edit options for this plugin.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    if ($form_state['section'] != 'exposed_form_options') {
      return;
    }
    $options = $this->display
      ->get_option('views_ef_fieldset');
    $defaults = $this
      ->option_definition();
    $form['views_ef_fieldset'] = array(
      '#tree' => TRUE,
    );
    $form['views_ef_fieldset']['enabled'] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($options['enabled']) ? $options['enabled'] : $defaults['views_ef_fieldset']['enabled']['default'],
      '#title' => t('Enable fieldset around exposed forms ?'),
    );
    $form['views_ef_fieldset']['options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Exposed form fieldsets'),
      '#states' => array(
        'visible' => array(
          ':input[name="views_ef_fieldset[enabled]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $exposed_fields = array_values($this->view->display_handler
      ->get_handlers('filter'));
    foreach ($exposed_fields as $exposed_field_index => $exposed_field) {
      if (!$exposed_field
        ->can_expose() || !$exposed_field
        ->is_exposed()) {
        unset($exposed_fields[$exposed_field_index]);
      }
    }
    $sort_fields = array_values($this->view->display_handler
      ->get_handlers('sort'));
    foreach ($sort_fields as $sort_fields_index => $sort_field) {
      if (!$sort_field
        ->can_expose() || !$sort_field
        ->is_exposed()) {
        unset($sort_fields[$sort_fields_index]);
      }
    }
    if (!empty($sort_fields)) {
      $sort_by = new Stdclass();
      $sort_by->handler_type = 'sort';
      $sort_by->options = array(
        'id' => 'sort_by',
        'expose' => array(
          'label' => 'Sort by',
        ),
      );
      $exposed_fields[] = $sort_by;
    }
    if ($form['exposed_form_options']['expose_sort_order']['#default_value'] == 1 && count($sort_fields)) {
      $sort_order = new Stdclass();
      $sort_order->handler_type = 'sort';
      $sort_order->options = array(
        'id' => 'sort_order',
        'expose' => array(
          'label' => 'Sort order',
        ),
      );
      $exposed_fields[] = $sort_order;
    }
    $submit_button = new Stdclass();
    $submit_button->handler_type = 'buttons';
    $submit_button->options = array(
      'id' => 'submit',
      'expose' => array(
        'label' => 'Submit button',
      ),
    );
    $exposed_fields[] = $submit_button;
    if ($form['exposed_form_options']['reset_button']['#default_value'] == 1) {
      $reset_button = new Stdclass();
      $reset_button->handler_type = 'buttons';
      $reset_button->options = array(
        'id' => 'reset',
        'expose' => array(
          'label' => 'Reset button',
        ),
      );
      $exposed_fields[] = $reset_button;
    }
    foreach ($exposed_fields as $exposed_field_index => $exposed_field) {
      $container = new StdClass();
      $container->handler_type = 'container';
      $container->container_type = 'fieldset';
      $container->weight = $exposed_field_index;
      $container->options = array(
        'id' => 'container-' . $exposed_field_index,
        'expose' => array(
          'label' => 'Container ' . $exposed_field_index,
        ),
      );
      $exposed_fields[] = $container;
    }
    $root_options = !empty($options['options']['sort']['root']) ? $options['options']['sort']['root'] : array();

    // Add defaults
    $root_options += array(
      'title' => t('Filters'),
      'description' => '',
      'collapsible' => TRUE,
      'collapsed' => TRUE,
      'collapsed_if_no_exposed_input' => FALSE,
      'container_type' => 'fieldset',
    );
    $data = array(
      array(
        'id' => 'root',
        'type' => 'container',
        'weight' => 0,
        'pid' => '',
        'label' => 'Root',
        'title' => $root_options['title'],
        'description' => $root_options['description'],
        'collapsible' => (bool) $root_options['collapsible'],
        'collapsed' => (bool) $root_options['collapsed'],
        'collapsed_if_no_exposed_input' => (bool) $root_options['collapsed_if_no_exposed_input'],
        'container_type' => $root_options['container_type'],
      ),
    );
    foreach ($exposed_fields as $index => $field) {
      $field_options = $options['options']['sort'][$field->options['id']];
      $label = $field->options['expose']['label'] ? $field->options['expose']['label'] : $field->options['id'];
      $data[] = array(
        'id' => $field->options['id'],
        'type' => $field->handler_type,
        'weight' => isset($field_options['weight']) ? $field_options['weight'] : (isset($field->weight) ? $field->weight : $index - count($exposed_fields)),
        'pid' => empty($field_options['pid']) ? 'root' : $field_options['pid'],
        'label' => $label,
        'title' => isset($field_options['title']) ? $field_options['title'] : $label,
        'description' => isset($field_options['description']) ? $field_options['description'] : '',
        'collapsible' => !empty($field_options['collapsible']),
        'collapsed' => !empty($field_options['collapsed']),
        'collapsed_if_no_exposed_input' => !empty($field_options['collapsed_if_no_exposed_input']),
        'container_type' => isset($field_options['container_type']) ? $field_options['container_type'] : 'fieldset',
      );
    }
    $viewsEFFieldsetData = new ViewsEFFieldsetData($data);
    $table_rows = array();
    foreach ($viewsEFFieldsetData
      ->buildFlat() as $item) {
      $item = $item['item'];
      $table_rows[$item['id']] = array(
        'weight' => array(
          '#item' => $item,
          '#type' => 'weight',
          '#title' => $item['title'],
          '#delta' => count($data),
          '#title_display' => 'invisible',
          '#default_value' => $item['weight'],
          '#attributes' => array(
            'class' => array(
              'item-weight',
            ),
          ),
        ),
        'type' => array(
          '#type' => 'hidden',
          '#default_value' => $item['type'],
        ),
        'id' => array(
          '#type' => 'hidden',
          '#default_value' => $item['id'],
          '#size' => 4,
          '#attributes' => array(
            'class' => array(
              'item-id',
            ),
          ),
        ),
        'pid' => array(
          '#type' => 'hidden',
          '#default_value' => $item['pid'],
          '#size' => 4,
          '#attributes' => array(
            'class' => array(
              'item-pid',
            ),
          ),
        ),
        'depth' => array(
          '#type' => 'hidden',
          '#default_value' => $item['depth'],
        ),
      );
      if ($item['type'] == 'container') {
        $table_rows[$item['id']] += array(
          'container_type' => array(
            '#type' => 'select',
            '#default_value' => $item['container_type'],
            '#options' => array(
              'container' => 'Container',
              'fieldset' => 'Fieldset',
              'vertical_tabs' => 'Vertical tabs',
            ),
          ),
          'title' => array(
            '#type' => 'textfield',
            '#size' => 15,
            '#default_value' => $item['title'],
          ),
          'description' => array(
            '#type' => 'textfield',
            '#size' => 15,
            '#default_value' => $item['description'],
          ),
          'collapsible' => array(
            '#type' => 'checkbox',
            '#default_value' => $item['collapsible'],
          ),
          'collapsed' => array(
            '#type' => 'checkbox',
            '#default_value' => $item['collapsed'],
          ),
          'collapsed_if_no_exposed_input' => array(
            '#type' => 'checkbox',
            '#default_value' => $item['collapsed_if_no_exposed_input'],
          ),
        );
      }
    }
    $form['views_ef_fieldset']['options']['sort'] = $table_rows;
    $form['views_ef_fieldset']['options']['sort']['#theme'][] = 'views_ef_fieldset_reorder_form';
  }
  function options_validate(&$form, &$form_state) {
    parent::options_validate($form, $form_state);
    $sort_options = array();
    if (array_key_exists('views_ef_fieldset', $form_state['values'])) {
      $sort_options = $form_state['values']['views_ef_fieldset']['options']['sort'];
    }
    if (!empty($sort_options)) {
      foreach ($sort_options as $item) {
        $parent = $sort_options[$item['pid']];
        if (is_array($parent)) {
          if ($parent['type'] != 'container') {
            form_set_error($item['id'], 'The item ' . $item['id'] . ' must be the child of a container only.');
          }
        }
      }
    }
  }
  function options_submit(&$form, &$form_state) {
    if (array_key_exists('views_ef_fieldset', $form_state['values'])) {
      $this->display
        ->set_option('views_ef_fieldset', $form_state['values']['views_ef_fieldset']);
    }
    parent::options_submit($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_ef_fieldset_display_extender_plugin::options_definition_alter function Provide a form to edit options for this plugin. Overrides views_plugin_display_extender::options_definition_alter
views_ef_fieldset_display_extender_plugin::options_form function Provide a form to edit options for this plugin. Overrides views_plugin_display_extender::options_form
views_ef_fieldset_display_extender_plugin::options_submit function Handle any special handling on the validate form. Overrides views_plugin_display_extender::options_submit
views_ef_fieldset_display_extender_plugin::options_validate function Validate the options form. Overrides views_plugin_display_extender::options_validate
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::option_definition public function Information about options for all kinds of purposes will be held here. 13
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::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_display_extender::defaultable_sections public function Static member function to list which sections are defaultable and what items each section contains.
views_plugin_display_extender::init public function
views_plugin_display_extender::options_summary public function Provide the default summary for options in the views UI.
views_plugin_display_extender::pre_execute public function Set up any variables on the view prior to execution.
views_plugin_display_extender::query public function Inject anything into the query that the display_extender handler needs. Overrides views_plugin::query