Respond to a form view ajax or redirect
@param array $params
@param \Form $form
@param string $redirect
@return \SS_HTTPResponse|null
556494
public function respondToFormAppropriately(array $params, $form = null, $redirect = '')
    {
        if ($redirect && !isset($params['redirect'])) {
            $params['redirect'] = $redirect;
        }

        if ($this->owner->Request->isAjax()) {
            if (!isset($params['code'])) {
                $params['code'] = 200;
            }
            if (!isset($params['code'])) {
                $params['status'] = 'success';
            }

            return singleton('director')->ajax_response($params, $params['code'], $params['status']);
        } else {
            if (isset($params['redirect'])) {
                $this->owner->redirect($params['redirect']);
            }

            if ($form && isset($params['message'])) {
                $form->sessionMessage($params['message'], 'good');
            }

            if (!$this->owner->redirectedTo()) {
                $this->owner->redirectBack();
            }
        }
    }
847212
public function success(Form $form) : void
    {
        if ($this->presenter->isAjax())
        {
            $values = $form->getValues();

            try
            {
                $redirect = NULL;
                $page = $this->pageRepository->findOneById($values->pageId);

                if ($this->redirectId)
                {
                    $redirect = $this->onPageRepository->findOneRedirectById($this->redirectId);
                }

                $this->onPageManager->saveRedirect($redirect, $page, $values->oldUrl);

                $form->reset();

                $this->presenter->notificationAjax(
                    'URL přesměrována',
                    'URL byla úspěšně přesměrována.',
                    'success',
                    FALSE
                );

                $this->onSave();
            }
            catch (DatabaseException $exception)
            {
                $this->presenter->notificationAjax(
                    'Chyba',
                    $exception->getMessage(),
                    'error'
                );
            }
        }
    }
479401
protected function redirect(string $ref, array $params = [], string $schema = null)
    {
        $url = $this->link($ref, $params, $schema);

        $response = new Response();
        $response->setCode(Response::CODE_REDIRECT_SEE_OTHER);
        $response->addHeader('Location', $url);

        return $response;
    }
1038827
public function redirect() : ?RedirectResponse
    {
        if (!$this->enabled()) {
            return null;
        }

        return redirect()
            ->back()
            ->withErrors([
                'form-verify-error' => $this->redirectMessage,
            ])
            ->withInput();
    }
1218062
final public static function redirectToRoute(
        string $routename,
        array $params = array(),
        bool $domain = true,
        array $query = array(),
        int $status = 302
    ):void {

        $querystring = $domainstring = "";
        $route = self::generateRoute($routename, $params);
        if (!empty($query)) {
            foreach ($query as $one => $value) {
                $querystring .= "$one=$value".(((end($query) !== $value))? "&": "");
            }
            $querystring = "?$querystring";
        }

        if (true === $domain) {
            $server = new GlobalServer();
            $https = ((null !== $server->get("HTTPS") &&
                "on" === $server->get("HTTPS"))? "https://" : "http://");
            $domain = $https.$server->get("HTTP_HOST");
        }
        header("Location: $domain$route$querystring", $status);
        exit(1);
    }
1221877
public function redirect($url = null, $statusCode = 302, $options = array())
    {
        $this->setStatusCode($statusCode);
        $this->setOption($options);

        // The variables for custom redirect view
        $escapedUrl = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
        $wait = (int)$this->redirectWait;

        // Location header does not support delay
        if (0 === $wait) {
            $this->setHeader('Location', $url);
        }

        // Prepare response content
        if ($this->redirectView) {
            ob_start();
            require $this->redirectView;
            $content = ob_get_clean();
        } else {
            $content = sprintf('<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="refresh" content="%d;url=%2$s">
    <title>Redirecting to %s</title>
  </head>
  <body>
    <h1>Redirecting to <a href="%2$s">%2$s</a></h1>
  </body>
</html>', $wait, $escapedUrl);
        }

        return $this->setContent($content);
    }
400690
public function redirectToRoute($route, array $params = [], $permanent = false)
    {
        $map = $this->app()->getRouteMap();
        $url = $map->assemble($route, $params);

        return $this->redirect($url, $permanent);
    }
102751
public function redirect($params = null, $atClientSide = false)
    {
        $this->setQueryString($params);

        ob_clean();
        header('Location: ' . $this->requestUrl);
        if ($atClientSide) {
            echo "<script language='javascript'>window.top.location = '" . $this->requestUrl . "'; </script>";
        }
    }
1000866
public function save($urlParams, $form) {

		// Retrieve the record.

		$record = null;
		if (isset($urlParams['ID'])) {
			$record = ExternalContent::getDataObjectFor($urlParams['ID']);
		}
		if (!$record) {
			return parent::save($urlParams, $form);
		}

		if ($record->canEdit()) {
			// lets load the params that have been sent and set those that have an editable mapping
			if ($record->hasMethod('editableFieldMapping')) {
				$editable = $record->editableFieldMapping();
				$form->saveInto($record, array_keys($editable));
				$record->remoteWrite();
			} else {
				$form->saveInto($record);
				$record->write();
			}

			// Set the form response.

			$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
		} else {
			$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'You don\'t have write access.')));
		}
		return $this->getResponseNegotiator()->respond($this->request);
	}
1186628
public function setRedirect(FormEvent $event)
    {
        $targetPath = $this->getTargetPath($event->getRequest());

        if ($targetPath) {
            $event->setResponse(new RedirectResponse($targetPath));

            return;
        }

        $this->setRedirecToLogin($event);
    }
769004
public function indexAction(Request $request)
    {
        /** @var RedirectionRepository $errorRepository */
        $redirectionRepository = $this->getDoctrine()->getManager()->getRepository('VictoireSeoBundle:Redirection');

        // Fetch errors

        /** @var QueryBuilder $redirections */
        $redirections = $redirectionRepository->getUnresolvedQuery()->getQuery()->getResult();

        // Build forms

        $forms = [];

        /** @var Redirection[] $redirection */
        foreach ($redirections as $redirection) {
            $forms[$redirection->getId()] = $this->getRedirectionForm($redirection,
                sprintf('#redirection-%d-item-container', $redirection->getId())
            )->createView();
        }

        $newForm = $this->getRedirectionForm(new Redirection(), '#new-redirection-form-container')->createView();

        // Return datas

        return new Response($this->renderView('@VictoireSeo/Redirection/index.html.twig', [
            'newForm'      => $newForm,
            'redirections' => $redirections,
            'forms'        => $forms,
        ]));
    }
1314814
private function getError404RedirectionForm(ErrorRedirection $redirection)
    {
        $action = $this->generateUrl('victoire_404_redirect', ['id' => $redirection->getError()->getId()]);

        $containerId = sprintf('#404-%d-item-container', $redirection->getError()->getId());

        return $this->createForm(RedirectionType::class, $redirection, [
            'method'      => 'POST',
            'action'      => $action,
            'containerId' => $containerId,
            'attr'        => [
                'v-ic-post-to' => $action,
                'v-ic-target'  => 'closest li',
            ],
        ]);
    }
338747
public function redirect($routeName, $controllerName = NULL, $params = [], $code = 302)
    {
        return new Redirect($routeName, $controllerName, $params, $code);
    }
422493
public static function redirectTo($module, $controller = 'index', array $params = []): void
    {
        $url = Router::getFullUrl($module, $controller, $params);
        self::redirect($url);
    }
579292
public function handleRedirect(RedirectEvent $event)
    {
        /** @var Controller $controllerAdapter */
        $controllerAdapter = $this->framework->getAdapter(Controller::class);

        $controllerAdapter->redirect($event->getNewLocation(), $event->getStatusCode());
    }
350015
public function redirect(string $page, array $params = [])
    {
        // Redirects with the url function
        header('Location: ' . $this->url($page, $params));
        exit;
    }
136833
public function create(Redirect &$redirect)
    {
        $endpoint = '/admin/redirects.json';
        $data = $redirect->exportData();
        $response = $this->request(
            $endpoint, "POST", array(
            'redirect' => $data
            )
        );
        $redirect->setData($response['redirect']);
    }