aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php45
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;
11use Wallabag\CoreBundle\Entity\Entry; 11use Wallabag\CoreBundle\Entity\Entry;
12use Wallabag\CoreBundle\Entity\Tag; 12use Wallabag\CoreBundle\Entity\Tag;
13use Wallabag\CoreBundle\Form\Type\NewTagType; 13use Wallabag\CoreBundle\Form\Type\NewTagType;
14use Wallabag\CoreBundle\Form\Type\RenameTagType;
14 15
15class TagController extends Controller 16class 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}