You are here

function views_ui_config_item_form_submit in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 8.3 views_ui/admin.inc \views_ui_config_item_form_submit()
  2. 6.3 includes/admin.inc \views_ui_config_item_form_submit()
  3. 6.2 includes/admin.inc \views_ui_config_item_form_submit()

Submit handler for configing new item(s) to a view.

File

includes/admin.inc, line 4621
Provides the Views' administrative interface.

Code

function views_ui_config_item_form_submit($form, &$form_state) {

  // Run it through the handler's submit function.
  $form_state['handler']
    ->options_submit($form['options'], $form_state);
  $item = $form_state['handler']->options;
  $types = views_object_types();

  // For footer/header $handler_type is area but $type is footer/header.
  // For all other handle types it's the same.
  $handler_type = $type = $form_state['type'];
  if (!empty($types[$type]['type'])) {
    $handler_type = $types[$type]['type'];
  }
  $override = NULL;
  if ($form_state['view']->display_handler
    ->use_group_by() && !empty($item['group_type'])) {
    if (empty($form_state['view']->query)) {
      $form_state['view']
        ->init_query();
    }
    $aggregate = $form_state['view']->query
      ->get_aggregation_info();
    if (!empty($aggregate[$item['group_type']]['handler'][$type])) {
      $override = $aggregate[$item['group_type']]['handler'][$type];
    }
  }

  // Create a new handler and unpack the options from the form onto it. We
  // can use that for storage.
  $handler = views_get_handler($item['table'], $item['field'], $handler_type, $override);
  $handler
    ->init($form_state['view'], $item);

  // Add the incoming options to existing options because items using
  // the extra form may not have everything in the form here.
  $options = $form_state['values']['options'] + $form_state['handler']->options;

  // This unpacks only options that are in the definition, ensuring random
  // extra stuff on the form is not sent through.
  $handler
    ->unpack_options($handler->options, $options, NULL, FALSE);

  // Store the item back on the view.
  $form_state['view']
    ->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], $handler->options);

  // Ensure any temporary options are removed.
  if (isset($form_state['view']->temporary_options[$type][$form_state['id']])) {
    unset($form_state['view']->temporary_options[$type][$form_state['id']]);
  }

  // Write to cache.
  views_ui_cache_set($form_state['view']);
}