public function ViewUI::addFormToStack

Add another form to the stack; clicking 'apply' will go to this form rather than closing the ajax popup.

1 call to ViewUI::addFormToStack()
ViewUI::submitItemAdd in drupal/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php
Submit handler for adding new item(s) to a view.

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php, line 380
Definition of Drupal\views_ui\ViewUI.

Class

ViewUI
Stores UI related temporary settings.

Namespace

Drupal\views_ui

Code

public function addFormToStack($key, $display_id, $type, $id = NULL, $top = FALSE, $rebuild_keys = FALSE) {

  // Reset the cache of IDs. Drupal rather aggressively prevents ID
  // duplication but this causes it to remember IDs that are no longer even
  // being used.
  $seen_ids_init =& drupal_static('drupal_html_id:init');
  $seen_ids_init = array();
  if (empty($this->stack)) {
    $this->stack = array();
  }
  $stack = array(
    implode('-', array_filter(array(
      $key,
      $this
        ->id(),
      $display_id,
      $type,
      $id,
    ))),
    $key,
    $display_id,
    $type,
    $id,
  );

  // If we're being asked to add this form to the bottom of the stack, no
  // special logic is required. Our work is equally easy if we were asked to add
  // to the top of the stack, but there's nothing in it yet.
  if (!$top || empty($this->stack)) {
    $this->stack[] = $stack;
  }
  else {
    $keys = array_keys($this->stack);
    $first = current($keys);
    $last = end($keys);
    for ($i = $last; $i >= $first; $i--) {
      if (!isset($this->stack[$i])) {
        continue;
      }

      // Move form number $i to the next position in the stack.
      $this->stack[$i + 1] = $this->stack[$i];
      unset($this->stack[$i]);
    }

    // Now that the previously $first slot is free, move the new form into it.
    $this->stack[$first] = $stack;
    ksort($this->stack);

    // Start the keys from 0 again, if requested.
    if ($rebuild_keys) {
      $this->stack = array_values($this->stack);
    }
  }
}