aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/TagController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index b6d28e59..d0155c60 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -5,12 +5,13 @@ namespace Wallabag\CoreBundle\Controller;
5use Pagerfanta\Adapter\ArrayAdapter; 5use Pagerfanta\Adapter\ArrayAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
10use 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}