diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 15f06ff5..d0155c60 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -11,6 +11,7 @@ use Symfony\Component\Routing\Annotation\Route; | |||
11 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
12 | use Wallabag\CoreBundle\Entity\Tag; | 12 | use Wallabag\CoreBundle\Entity\Tag; |
13 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 13 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
14 | use Wallabag\CoreBundle\Form\Type\RenameTagType; | ||
14 | 15 | ||
15 | class TagController extends Controller | 16 | class TagController extends Controller |
16 | { | 17 | { |
@@ -87,8 +88,14 @@ class TagController extends Controller | |||
87 | $tags = $this->get('wallabag_core.tag_repository') | 88 | $tags = $this->get('wallabag_core.tag_repository') |
88 | ->findAllFlatTagsWithNbEntries($this->getUser()->getId()); | 89 | ->findAllFlatTagsWithNbEntries($this->getUser()->getId()); |
89 | 90 | ||
91 | $renameForms = []; | ||
92 | foreach ($tags as $tag) { | ||
93 | $renameForms[$tag['id']] = $this->createForm(RenameTagType::class, new Tag())->createView(); | ||
94 | } | ||
95 | |||
90 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ | 96 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ |
91 | 'tags' => $tags, | 97 | 'tags' => $tags, |
98 | 'renameForms' => $renameForms, | ||
92 | ]); | 99 | ]); |
93 | } | 100 | } |
94 | 101 | ||
@@ -130,4 +137,48 @@ class TagController extends Controller | |||
130 | 'tag' => $tag, | 137 | 'tag' => $tag, |
131 | ]); | 138 | ]); |
132 | } | 139 | } |
140 | |||
141 | /** | ||
142 | * Rename a given tag with a new label | ||
143 | * Create a new tag with the new name and drop the old one. | ||
144 | * | ||
145 | * @param Tag $tag | ||
146 | * @param Request $request | ||
147 | * | ||
148 | * @Route("/tag/rename/{slug}", name="tag_rename") | ||
149 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
150 | * | ||
151 | * @return \Symfony\Component\HttpFoundation\Response | ||
152 | */ | ||
153 | public function renameTagAction(Tag $tag, Request $request) | ||
154 | { | ||
155 | $form = $this->createForm(RenameTagType::class, new Tag()); | ||
156 | $form->handleRequest($request); | ||
157 | |||
158 | if ($form->isSubmitted() && $form->isValid()) { | ||
159 | $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( | ||
160 | $this->getUser()->getId(), | ||
161 | $tag->getId() | ||
162 | ); | ||
163 | foreach ($entries as $entry) { | ||
164 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( | ||
165 | $entry, | ||
166 | $form->get('label')->getData() | ||
167 | ); | ||
168 | $entry->removeTag($tag); | ||
169 | } | ||
170 | |||
171 | $em = $this->getDoctrine()->getManager(); | ||
172 | $em->flush(); | ||
173 | } | ||
174 | |||
175 | $this->get('session')->getFlashBag()->add( | ||
176 | 'notice', | ||
177 | 'flashes.tag.notice.tag_renamed' | ||
178 | ); | ||
179 | |||
180 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); | ||
181 | |||
182 | return $this->redirect($redirectUrl); | ||
183 | } | ||
133 | } | 184 | } |