21
21
use Symfony \Component \HttpFoundation \Request ;
22
22
use Symfony \Component \HttpFoundation \Response ;
23
23
use Symfony \Component \Routing \Annotation \Route ;
24
- use Symfony \Component \String \Slugger \SluggerInterface ;
25
24
26
25
/**
27
26
* Controller used to manage blog contents in the backend.
@@ -70,7 +69,7 @@ public function index(PostRepository $posts): Response
70
69
* to constraint the HTTP methods each controller responds to (by default
71
70
* it responds to all methods).
72
71
*/
73
- public function new (Request $ request, SluggerInterface $ slugger ): Response
72
+ public function new (Request $ request ): Response
74
73
{
75
74
$ post = new Post ();
76
75
$ post ->setAuthor ($ this ->getUser ());
@@ -86,8 +85,6 @@ public function new(Request $request, SluggerInterface $slugger): Response
86
85
// However, we explicitly add it to improve code readability.
87
86
// See https://symfony.com/doc/current/forms.html#processing-forms
88
87
if ($ form ->isSubmitted () && $ form ->isValid ()) {
89
- $ post ->setSlug ($ slugger ->slug ($ post ->getTitle ())->lower ());
90
-
91
88
$ em = $ this ->getDoctrine ()->getManager ();
92
89
$ em ->persist ($ post );
93
90
$ em ->flush ();
@@ -133,13 +130,12 @@ public function show(Post $post): Response
133
130
* @Route("/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
134
131
* @IsGranted("edit", subject="post", message="Posts can only be edited by their authors.")
135
132
*/
136
- public function edit (Request $ request , Post $ post, SluggerInterface $ slugger ): Response
133
+ public function edit (Request $ request , Post $ post ): Response
137
134
{
138
135
$ form = $ this ->createForm (PostType::class, $ post );
139
136
$ form ->handleRequest ($ request );
140
137
141
138
if ($ form ->isSubmitted () && $ form ->isValid ()) {
142
- $ post ->setSlug ($ slugger ->slug ($ post ->getTitle ())->lower ());
143
139
$ this ->getDoctrine ()->getManager ()->flush ();
144
140
145
141
$ this ->addFlash ('success ' , 'post.updated_successfully ' );
0 commit comments