function ViewEditForm::submitDelayDestination

Same name in other branches
  1. 9 core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::submitDelayDestination()
  2. 8.9.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::submitDelayDestination()
  3. 11.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::submitDelayDestination()

Submit handler for form buttons that do not complete a form workflow.

The Edit View form is a multistep form workflow, but with state managed by the SharedTempStore rather than $form_state->setRebuild(). Without this submit handler, buttons that add or remove displays would redirect to the destination parameter (e.g., when the Edit View form is linked to from a contextual link). This handler can be added to buttons whose form submission should not yet redirect to the destination.

File

core/modules/views_ui/src/ViewEditForm.php, line 858

Class

ViewEditForm
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

public function submitDelayDestination($form, FormStateInterface $form_state) {
    $request = $this->requestStack
        ->getCurrentRequest();
    $destination = $request->query
        ->get('destination');
    $redirect = $form_state->getRedirect();
    // If there is a destination, and redirects are not explicitly disabled, add
    // the destination as a query string to the redirect and suppress it for the
    // current request.
    if (isset($destination) && $redirect !== FALSE) {
        // Create a valid redirect if one does not exist already.
        if (!$redirect instanceof Url) {
            $redirect = Url::createFromRequest($request);
        }
        // Add the current destination to the redirect unless one exists already.
        $options = $redirect->getOptions();
        if (!isset($options['query']['destination'])) {
            $options['query']['destination'] = $destination;
            $redirect->setOptions($options);
        }
        $form_state->setRedirectUrl($redirect);
        $request->query
            ->remove('destination');
    }
}

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