forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuccessstream-update-review-stream.diff
34 lines (29 loc) · 1.48 KB
/
successstream-update-review-stream.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
diff --git a/src/Controller/ProductController.php b/src/Controller/ProductController.php
index 753be33..73e655a 100644
--- a/src/Controller/ProductController.php
+++ b/src/Controller/ProductController.php
@@ -83,23 +83,19 @@ class ProductController extends AbstractController
if ($request->isMethod('POST')) {
$this->denyAccessUnlessGranted('ROLE_USER');
- $update = new Update(
- 'product-reviews',
- '<turbo-stream action="update" target="product-quick-stats"><template>QUICK STATS CHANGED!</template></turbo-stream>'
- );
- $mercureHub->publish($update);
-
$reviewForm->handleRequest($request);
if ($reviewForm->isSubmitted() && $reviewForm->isValid()) {
$entityManager->persist($reviewForm->getData());
$entityManager->flush();
- if (TurboStreamResponse::STREAM_FORMAT === $request->getPreferredFormat()) {
- return $this->render('product/reviews.stream.html.twig', [
+ $update = new Update(
+ 'product-reviews',
+ $this->render('product/reviews.stream.html.twig', [
'product' => $product,
- ], new TurboStreamResponse());
- }
+ ]),
+ );
+ $mercureHub->publish($update);
$this->addFlash('review_success', 'Thanks for your review! I like you!');