forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixredirect-add-shouldwrapredirect.diff
44 lines (41 loc) · 1.4 KB
/
fixredirect-add-shouldwrapredirect.diff
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
35
36
37
38
39
40
41
42
43
44
diff --git a/src/EventSubscriber/TurboFrameRedirectSubscriber.php b/src/EventSubscriber/TurboFrameRedirectSubscriber.php
index eec0218..eee47c6 100644
--- a/src/EventSubscriber/TurboFrameRedirectSubscriber.php
+++ b/src/EventSubscriber/TurboFrameRedirectSubscriber.php
@@ -3,12 +3,17 @@
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class TurboFrameRedirectSubscriber implements EventSubscriberInterface
{
public function onKernelResponse(ResponseEvent $event)
{
+ if (!$this->shouldWrapRedirect($event->getRequest(), $event->getResponse())) {
+ return;
+ }
}
public static function getSubscribedEvents()
@@ -17,4 +22,21 @@ class TurboFrameRedirectSubscriber implements EventSubscriberInterface
ResponseEvent::class => 'onKernelResponse',
];
}
+
+ private function shouldWrapRedirect(Request $request, Response $response): bool
+ {
+ if (!$response->isRedirection()) {
+ return false;
+ }
+
+ if (!$request->headers->has('Turbo-Frame')) {
+ return false;
+ }
+
+ if ($request->headers->get('Turbo-Frame-Redirect')) {
+ return true;
+ }
+
+ return false;
+ }
}