function FormSubmitter::redirectForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/FormSubmitter.php \Drupal\Core\Form\FormSubmitter::redirectForm()
  2. 10 core/lib/Drupal/Core/Form/FormSubmitter.php \Drupal\Core\Form\FormSubmitter::redirectForm()
  3. 11.x core/lib/Drupal/Core/Form/FormSubmitter.php \Drupal\Core\Form\FormSubmitter::redirectForm()

Overrides FormSubmitterInterface::redirectForm

1 call to FormSubmitter::redirectForm()
FormSubmitter::doSubmitForm in core/lib/Drupal/Core/Form/FormSubmitter.php
Handles the submitted form, executing callbacks and processing responses.

File

core/lib/Drupal/Core/Form/FormSubmitter.php, line 122

Class

FormSubmitter
Provides submission processing for forms.

Namespace

Drupal\Core\Form

Code

public function redirectForm(FormStateInterface $form_state) {
    $redirect = $form_state->getRedirect();
    // Allow using redirect responses directly if needed.
    if ($redirect instanceof RedirectResponse) {
        return $redirect;
    }
    $url = NULL;
    // Check for a route-based redirection.
    if ($redirect instanceof Url) {
        $url = $redirect->setAbsolute()
            ->toString();
    }
    elseif ($redirect === NULL) {
        $request = $this->requestStack
            ->getCurrentRequest();
        $url = $this->urlGenerator
            ->generateFromRoute('<current>', [], [
            'query' => $request->query
                ->all(),
            'absolute' => TRUE,
        ]);
    }
    if ($url) {
        // According to RFC 7231, 303 See Other status code must be used to redirect
        // user agent (and not default 302 Found).
        // @see http://tools.ietf.org/html/rfc7231#section-6.4.4
        return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
    }
}

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