diff options
author | Stéphane HULARD <s.hulard@chstudio.fr> | 2018-01-24 17:27:16 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2018-09-25 10:18:08 +0200 |
commit | be326a22f90a5f4006ff41ee7b4ed0ca73a8fddd (patch) | |
tree | 9ab86f75f9cbf05733b3089f0f22b1512bcd1ab6 | |
parent | a664a1d876174e9d61d8324039ee86d2b6bf164d (diff) | |
download | wallabag-be326a22f90a5f4006ff41ee7b4ed0ca73a8fddd.tar.gz wallabag-be326a22f90a5f4006ff41ee7b4ed0ca73a8fddd.tar.zst wallabag-be326a22f90a5f4006ff41ee7b4ed0ca73a8fddd.zip |
Create a new Tag action to rename tags.
The current tag is removed from all the current logged user entries. Then the new one is created and attached.
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index b6d28e59..70b273e0 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request; | |||
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 | { |
@@ -130,4 +131,48 @@ class TagController extends Controller | |||
130 | 'tag' => $tag, | 131 | 'tag' => $tag, |
131 | ]); | 132 | ]); |
132 | } | 133 | } |
134 | |||
135 | /** | ||
136 | * Rename a given tag with a new label | ||
137 | * Create a new tag with the new name and drop the old one. | ||
138 | * | ||
139 | * @param Tag $tag | ||
140 | * @param Request $request | ||
141 | * | ||
142 | * @Route("/tag/rename/{slug}", name="tag_rename") | ||
143 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
144 | * | ||
145 | * @return \Symfony\Component\HttpFoundation\Response | ||
146 | */ | ||
147 | public function renameTagAction(Tag $tag, Request $request) | ||
148 | { | ||
149 | $form = $this->createForm(RenameTagType::class, new Tag()); | ||
150 | $form->handleRequest($request); | ||
151 | |||
152 | if ($form->isSubmitted() && $form->isValid()) { | ||
153 | $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( | ||
154 | $this->getUser()->getId(), | ||
155 | $tag->getId() | ||
156 | ); | ||
157 | foreach ($entries as $entry) { | ||
158 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( | ||
159 | $entry, | ||
160 | $form->get('label')->getData() | ||
161 | ); | ||
162 | $entry->removeTag($tag); | ||
163 | } | ||
164 | |||
165 | $em = $this->getDoctrine()->getManager(); | ||
166 | $em->flush(); | ||
167 | } | ||
168 | |||
169 | $this->get('session')->getFlashBag()->add( | ||
170 | 'notice', | ||
171 | 'flashes.tag.notice.tag_renamed' | ||
172 | ); | ||
173 | |||
174 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); | ||
175 | |||
176 | return $this->redirect($redirectUrl); | ||
177 | } | ||
133 | } | 178 | } |