function ViewUI::addFormToStack

Same name in other branches
  1. 9 core/modules/views_ui/src/ViewUI.php \Drupal\views_ui\ViewUI::addFormToStack()
  2. 10 core/modules/views_ui/src/ViewUI.php \Drupal\views_ui\ViewUI::addFormToStack()
  3. 11.x 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 382

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 = [];
    }
    $stack = [
        implode('-', array_filter([
            $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);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.