|
13 | 13 |
|
14 | 14 | use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
15 | 15 | use Symfony\Component\HttpFoundation\Cookie;
|
| 16 | +use Symfony\Component\HttpFoundation\Request; |
16 | 17 | use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
17 | 18 | use Symfony\Component\HttpFoundation\Session\Session;
|
18 | 19 | use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
@@ -87,26 +88,28 @@ public function onKernelResponse(FlashMessageResponseEvent $event)
|
87 | 88 | return;
|
88 | 89 | }
|
89 | 90 |
|
90 |
| - $response = $event->getResponse(); |
91 |
| - |
92 |
| - // If the response is a redirect, we should wait until the final response |
93 |
| - // is reached |
94 |
| - if ($response->isRedirect()) { |
95 |
| - return; |
96 |
| - } |
97 |
| - |
98 | 91 | $flashBag = $this->session->getFlashBag();
|
99 | 92 | $flashes = $flashBag->all();
|
100 | 93 |
|
101 | 94 | if (empty($flashes)) {
|
102 | 95 | return;
|
103 | 96 | }
|
104 | 97 |
|
| 98 | + $response = $event->getResponse(); |
| 99 | + |
105 | 100 | $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
106 | 101 | $host = (null === $this->options['host']) ? '' : $this->options['host'];
|
107 | 102 | if (isset($cookies[$host][$this->options['path']][$this->options['name']])) {
|
108 | 103 | $rawCookie = $cookies[$host][$this->options['path']][$this->options['name']]->getValue();
|
109 |
| - $flashes = array_merge($flashes, json_decode($rawCookie)); |
| 104 | + $flashes = array_merge_recursive($flashes, json_decode($rawCookie, true)); |
| 105 | + } |
| 106 | + |
| 107 | + // Preserve existing flash message cookie from previous redirect if there was one. |
| 108 | + // This covers multiple redirects where each redirect adds flash messages. |
| 109 | + $request = $event->getRequest(); |
| 110 | + if ($request->cookies->has($this->options['name'])) { |
| 111 | + $rawCookie = $request->cookies->get($this->options['name']); |
| 112 | + $flashes = array_merge_recursive($flashes, json_decode($rawCookie, true)); |
110 | 113 | }
|
111 | 114 |
|
112 | 115 | $cookie = new Cookie(
|
|
0 commit comments