You are here

function views_ui_add_item_form_submit in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 includes/admin.inc \views_ui_add_item_form_submit()
  2. 6.2 includes/admin.inc \views_ui_add_item_form_submit()

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

1 string reference to 'views_ui_add_item_form_submit'
views_ui_add_item_form in includes/admin.inc
Form to add_item items in the views UI.

File

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

Code

function views_ui_add_item_form_submit($form, &$form_state) {
  $type = $form_state['type'];
  $types = views_object_types();
  $section = $types[$type]['plural'];

  // Handle the override select.
  list($was_defaulted, $is_defaulted) = views_ui_standard_override_values($form, $form_state);
  if ($was_defaulted && !$is_defaulted) {

    // We were using the default display's values, but we're now overriding
    // the default display and saving values specific to this display.
    $display =& $form_state['view']->display[$form_state['display_id']];

    // set_override toggles the override of this section.
    $display->handler
      ->set_override($section);
  }
  elseif (!$was_defaulted && $is_defaulted) {

    // We used to have an override for this display, but the user now wants
    // to go back to the default display.
    // Overwrite the default display with the current form values, and make
    // the current display use the new default values.
    $display =& $form_state['view']->display[$form_state['display_id']];

    // options_override toggles the override of this section.
    $display->handler
      ->set_override($section);
  }
  if (!empty($form_state['values']['name']) && is_array($form_state['values']['name'])) {

    // Loop through each of the items that were checked and add them to the
    // view.
    foreach (array_keys(array_filter($form_state['values']['name'])) as $field) {
      list($table, $field) = explode('.', $field, 2);
      if ($cut = strpos($field, '$')) {
        $field = substr($field, 0, $cut);
      }
      $id = $form_state['view']
        ->add_item($form_state['display_id'], $type, $table, $field);

      // Check to see if we have group by settings.
      $key = $type;

      // Footer,header and empty text have a different internal handler type
      // (area).
      if (isset($types[$type]['type'])) {
        $key = $types[$type]['type'];
      }
      $handler = views_get_handler($table, $field, $key);
      if ($form_state['view']->display_handler
        ->use_group_by() && $handler
        ->use_group_by()) {
        views_ui_add_form_to_stack('config-item-group', $form_state['view'], $form_state['display_id'], array(
          $type,
          $id,
        ));
      }

      // Check to see if this type has settings, if so add the settings form
      // first.
      if ($handler && $handler
        ->has_extra_options()) {
        views_ui_add_form_to_stack('config-item-extra', $form_state['view'], $form_state['display_id'], array(
          $type,
          $id,
        ));
      }

      // Then add the form to the stack.
      views_ui_add_form_to_stack('config-item', $form_state['view'], $form_state['display_id'], array(
        $type,
        $id,
      ));
    }
  }
  if (isset($form_state['view']->form_cache)) {
    unset($form_state['view']->form_cache);
  }

  // Store in cache.
  views_ui_cache_set($form_state['view']);
}