You are here

public function ViewUI::submitItemAdd in Views (for Drupal 7) 8.3

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

File

views_ui/lib/Drupal/views_ui/ViewUI.php, line 1645
Definition of Drupal\views_ui\ViewUI.

Class

ViewUI
Stores UI related temporary settings.

Namespace

Drupal\views_ui

Code

public function submitItemAdd($form, &$form_state) {
  $type = $form_state['type'];
  $types = static::viewsHandlerTypes();
  $section = $types[$type]['plural'];

  // Handle the override select.
  list($was_defaulted, $is_defaulted) = $this
    ->getOverrideValues($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 =& $this->displayHandlers[$form_state['display_id']];

    // setOverride toggles the override of this section.
    $display
      ->setOverride($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 =& $this->displayHandlers[$form_state['display_id']];

    // optionsOverride toggles the override of this section.
    $display
      ->setOverride($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 = $this
        ->addItem($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 ($this->display_handler
        ->useGroupBy() && $handler
        ->usesGroupBy()) {
        $this
          ->addFormToStack('config-item-group', $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
        ->hasExtraOptions()) {
        $this
          ->addFormToStack('config-item-extra', $form_state['display_id'], array(
          $type,
          $id,
        ));
      }

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

  // Store in cache
  views_ui_cache_set($this);
}