aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/TagController.php
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2018-10-15 08:32:59 +0000
committerGitHub <noreply@github.com>2018-10-15 08:32:59 +0000
commite673b54f702f274a087e4feff409663d9636e57b (patch)
tree094dffaffc7f3f9ed1513e939083a922ee00b0cc /src/Wallabag/CoreBundle/Controller/TagController.php
parent5bb01c034424b56a0a0ae4bc34ae5bb9a514deba (diff)
parent84d59603c53878bfba32a8fb846d3c00e756c4f1 (diff)
downloadwallabag-e673b54f702f274a087e4feff409663d9636e57b.tar.gz
wallabag-e673b54f702f274a087e4feff409663d9636e57b.tar.zst
wallabag-e673b54f702f274a087e4feff409663d9636e57b.zip
Merge pull request #3574 from shulard/feature/rename-tags
Allow to rename tags from the web interface.
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php51
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;
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{
@@ -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}