You are here

public function ViewUI::addFormToStack in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/ViewUI.php \Drupal\views_ui\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 core/modules/views_ui/src/ViewUI.php
Submit handler for adding new item(s) to a view.

File

core/modules/views_ui/src/ViewUI.php, line 410
Contains \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.
  Html::resetSeenIds();
  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);
    }
  }
}