1.20.x views_plugin_display.inc views_plugin_display::options_submit(&$form, &$form_state)

Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.

Overrides views_plugin::options_submit

File

modules/views/plugins/views_plugin_display.inc, line 2306
Contains the base display plugin.

Class

views_plugin_display
The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

Code

function options_submit(&$form, &$form_state) {
  // Not sure I like this being here, but it seems (?) like a logical place.
  $cache_plugin = $this->get_plugin('cache');
  if ($cache_plugin) {
    $cache_plugin->cache_flush();
  }

  $section = $form_state['section'];
  switch ($section) {
    case 'display_id':
      if (isset($form_state['values']['display_id'])) {
        $this->display->new_id = $form_state['values']['display_id'];
      }
      break;
    case 'display_title':
      $this->display->display_title = $form_state['values']['display_title'];
      $this->set_option('display_description', $form_state['values']['display_description']);
      break;
    case 'access':
      $access = $this->get_option('access');
      if ($access['type'] != $form_state['values']['access']['type']) {
        $plugin = views_get_plugin('access', $form_state['values']['access']['type']);
        if ($plugin) {
          $access = array('type' => $form_state['values']['access']['type']);
          $this->set_option('access', $access);
          if (!empty($plugin->definition['uses options'])) {
            views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('access_options'));
          }
        }
      }

      break;
    case 'access_options':
      $plugin = views_get_plugin('access', $form_state['values'][$section]['type']);
      if ($plugin) {
        $plugin->options_submit($form['access_options'], $form_state);
        $this->set_option('access', $form_state['values'][$section]);
      }
      break;
    case 'cache':
      $cache = $this->get_option('cache');
      if ($cache['type'] != $form_state['values']['cache']['type']) {
        $plugin = views_get_plugin('cache', $form_state['values']['cache']['type']);
        if ($plugin) {
          $cache = array('type' => $form_state['values']['cache']['type']);
          $this->set_option('cache', $cache);
          if (!empty($plugin->definition['uses options'])) {
            views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('cache_options'));
          }
        }
      }

      break;
    case 'cache_options':
      $plugin = views_get_plugin('cache', $form_state['values'][$section]['type']);
      if ($plugin) {
        $plugin->options_submit($form['cache_options'], $form_state);
        $this->set_option('cache', $form_state['values'][$section]);
      }
      break;
    case 'query':
      $plugin = $this->get_plugin('query');
      if ($plugin) {
        $plugin->options_submit($form['query']['options'], $form_state);
        $this->set_option('query', $form_state['values'][$section]);
      }
      break;

    case 'link_display':
      $this->set_option('link_url', $form_state['values']['link_url']);
    case 'title':
    case 'css_class':
    case 'display_comment':
      $this->set_option($section, $form_state['values'][$section]);
      break;
    case 'field_language':
      $this->set_option('field_language', $form_state['values']['field_language']);
      $this->set_option('field_language_add_to_query', $form_state['values']['field_language_add_to_query']);
      break;
    case 'use_ajax':
    case 'hide_attachment_summary':
    case 'hide_admin_links':
      $this->set_option($section, (bool) $form_state['values'][$section]);
      break;
    case 'use_more':
      $this->set_option($section, intval($form_state['values'][$section]));
      $this->set_option('use_more_always', !intval($form_state['values']['use_more_always']));
      $this->set_option('use_more_text', $form_state['values']['use_more_text']);
    case 'distinct':
      $this->set_option($section, $form_state['values'][$section]);
      break;
    case 'group_by':
      $this->set_option($section, $form_state['values'][$section]);
      break;
    case 'row_plugin':
      // This if prevents resetting options to default if they don't change
      // the plugin.
      if ($this->get_option($section) != $form_state['values'][$section]) {
        $plugin = views_get_plugin('row', $form_state['values'][$section]);
        if ($plugin) {
          $this->set_option($section, $form_state['values'][$section]);
          $this->set_option('row_options', array());

          // send ajax form to options page if we use it.
          if (!empty($plugin->definition['uses options'])) {
            views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options'));
          }
        }
      }
      break;
    case 'style_plugin':
      // This if prevents resetting options to default if they don't change
      // the plugin.
      if ($this->get_option($section) != $form_state['values'][$section]) {
        $plugin = views_get_plugin('style', $form_state['values'][$section]);
        if ($plugin) {
          $this->set_option($section, $form_state['values'][$section]);
          $this->set_option('style_options', array());
          // send ajax form to options page if we use it.
          if (!empty($plugin->definition['uses options'])) {
            views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options'));
          }
        }
      }
      break;
    case 'style_options':
      $style = TRUE;
    case 'row_options':
      // if row, $style will be empty.
      $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
      if ($plugin) {
        $plugin->options_submit($form['options'][$section], $form_state);
      }
      $this->set_option($section, $form_state['values'][$section]);
      break;
    case 'exposed_block':
      $this->set_option($section, (bool) $form_state['values'][$section]);
      break;
    case 'exposed_form':
      $exposed_form = $this->get_option('exposed_form');
      if ($exposed_form['type'] != $form_state['values']['exposed_form']['type']) {
        $plugin = views_get_plugin('exposed_form', $form_state['values']['exposed_form']['type']);
        if ($plugin) {
          $exposed_form = array('type' => $form_state['values']['exposed_form']['type'], 'options' => array());
          $this->set_option('exposed_form', $exposed_form);
          if (!empty($plugin->definition['uses options'])) {
            views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('exposed_form_options'));
          }
        }
      }

      break;
    case 'exposed_form_options':
      $plugin = $this->get_plugin('exposed_form');
      if ($plugin) {
        $exposed_form = $this->get_option('exposed_form');
        $plugin->options_submit($form['exposed_form_options'], $form_state);
        $exposed_form['options'] = $form_state['values'][$section];
        $this->set_option('exposed_form', $exposed_form);
      }
      break;
    case 'pager':
      $pager = $this->get_option('pager');
      if ($pager['type'] != $form_state['values']['pager']['type']) {
        $plugin = views_get_plugin('pager', $form_state['values']['pager']['type']);
        if ($plugin) {
          // Because pagers have very similar options, let's allow pagers to
          // try to carry the options over.
          $plugin->init($this->view, $this->display, $pager['options']);

          $pager = array('type' => $form_state['values']['pager']['type'], 'options' => $plugin->options);
          $this->set_option('pager', $pager);
          if (!empty($plugin->definition['uses options'])) {
            views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('pager_options'));
          }
        }
      }

      break;
    case 'pager_options':
      $plugin = $this->get_plugin('pager');
      if ($plugin) {
        $pager = $this->get_option('pager');
        $plugin->options_submit($form['pager_options'], $form_state);
        $pager['options'] = $form_state['values'][$section];
        $this->set_option('pager', $pager);
      }
      break;
  }

  foreach ($this->extender as $extender) {
    $extender->options_submit($form, $form_state);
  }
}