forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-turbo-fixing-review-admin-area.diff
55 lines (50 loc) · 1.62 KB
/
pre-turbo-fixing-review-admin-area.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
45
46
47
48
49
50
51
52
53
54
55
diff --git a/src/Controller/ReviewAdminController.php b/src/Controller/ReviewAdminController.php
index fb60f56..5991758 100644
--- a/src/Controller/ReviewAdminController.php
+++ b/src/Controller/ReviewAdminController.php
@@ -30,7 +30,7 @@ class ReviewAdminController extends AbstractController
*/
public function new(Request $request): Response
{
- $review = new Review();
+ $review = new Review($this->getUser());
$form = $this->createForm(ReviewType::class, $review);
$form->handleRequest($request);
diff --git a/src/Entity/Review.php b/src/Entity/Review.php
index f411062..c032783 100644
--- a/src/Entity/Review.php
+++ b/src/Entity/Review.php
@@ -35,7 +35,7 @@ class Review
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="reviews")
* @ORM\JoinColumn(nullable=false)
*/
- private Product $product;
+ private ?Product $product;
/**
* @ORM\Column(type="integer")
@@ -45,7 +45,7 @@ class Review
*/
private ?int $stars;
- public function __construct(User $owner, Product $product)
+ public function __construct(User $owner, Product $product = null)
{
$this->owner = $owner;
$this->product = $product;
@@ -82,11 +82,18 @@ class Review
return $this->owner;
}
- public function getProduct(): Product
+ public function getProduct(): ?Product
{
return $this->product;
}
+ public function setProduct(Product $product): self
+ {
+ $this->product = $product;
+
+ return $this;
+ }
+
public function getStars(): ?int
{
return $this->stars;