-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRedirectBuilderTrait.php
34 lines (30 loc) · 1.04 KB
/
RedirectBuilderTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace Drupal\wmcontroller\Controller;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
trait RedirectBuilderTrait
{
/**
* Returns a redirect response object for the specified route.
*
* @param string $routeName
* The name of the route to which to redirect.
* @param array $routeParameters
* (optional) Parameters for the route.
* @param array $options
* (optional) An associative array of additional options.
* @param int $status
* (optional) The HTTP redirect status code for the redirect. The default is
* 302 Found.
*
* @return RedirectResponse
* A redirect response object that may be returned by the controller.
*/
protected function redirect(string $routeName, array $routeParameters = [], array $options = [], int $status = 302)
{
$url = Url::fromRoute($routeName, $routeParameters, $options)
->setAbsolute(true)
->toString();
return new RedirectResponse($url, $status);
}
}