3 namespace Wallabag\CoreBundle\Controller
;
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Wallabag\CoreBundle\Entity\Entry
;
9 use Wallabag\CoreBundle\Entity\Tag
;
10 use Wallabag\CoreBundle\Form\Type\NewTagType
;
12 class TagController
extends Controller
15 * @param Request $request
18 * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag")
20 * @return \Symfony\Component\HttpFoundation\Response
22 public function addTagFormAction(Request
$request, Entry
$entry)
24 $form = $this->createForm(NewTagType
::class, new Tag());
25 $form->handleRequest($request);
27 if ($form->isValid()) {
28 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
30 $form->get('label')->getData()
33 $em = $this->getDoctrine()->getManager();
37 $this->get('session')->getFlashBag()->add(
39 'flashes.tag.notice.tag_added'
42 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
45 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', [
46 'form' => $form->createView(),
52 * Removes tag from entry.
54 * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
56 * @return \Symfony\Component\HttpFoundation\Response
58 public function removeTagFromEntry(Request
$request, Entry
$entry, Tag
$tag)
60 $entry->removeTag($tag);
61 $em = $this->getDoctrine()->getManager();
63 if (count($tag->getEntries()) == 0) {
68 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers
->get('referer'));
70 return $this->redirect($redirectUrl);
74 * Shows tags for current user.
76 * @Route("/tag/list", name="tag")
78 * @return \Symfony\Component\HttpFoundation\Response
80 public function showTagAction()
82 $tags = $this->getDoctrine()
83 ->getRepository('WallabagCoreBundle:Tag')
84 ->findAllTags($this->getUser()->getId());
87 'WallabagCoreBundle:Tag:tags.html.twig',