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
17 * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag")
19 * @return \Symfony\Component\HttpFoundation\Response
21 public function addTagFormAction(Request
$request, Entry
$entry)
24 $form = $this->createForm(NewTagType
::class, $tag);
25 $form->handleRequest($request);
27 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine()
29 ->getRepository('WallabagCoreBundle:Tag')
30 ->findOneByLabel($tag->getLabel());
32 $em = $this->getDoctrine()->getManager();
34 if (is_null($existingTag)) {
35 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
40 } elseif (!$existingTag->hasEntry($entry)) {
41 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
45 $em->persist($existingTag);
50 $this->get('session')->getFlashBag()->add(
52 'flashes.tag.notice.tag_added'
55 return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
58 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', array(
59 'form' => $form->createView(),
65 * Removes tag from entry.
67 * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
69 * @return \Symfony\Component\HttpFoundation\Response
71 public function removeTagFromEntry(Request
$request, Entry
$entry, Tag
$tag)
73 $entry->removeTag($tag);
74 $em = $this->getDoctrine()->getManager();
76 if (count($tag->getEntries()) == 0) {
81 return $this->redirect($request->headers
->get('referer'));
85 * Shows tags for current user.
87 * @Route("/tag/list", name="tag")
89 * @return \Symfony\Component\HttpFoundation\Response
91 public function showTagAction()
93 $tags = $this->getDoctrine()
94 ->getRepository('WallabagCoreBundle:Tag')
95 ->findTags($this->getUser()->getId());
98 'WallabagCoreBundle:Tag:tags.html.twig',