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)) {
37 } elseif (!$existingTag->hasEntry($entry)) {
38 $entry->addTag($existingTag);
39 $em->persist($existingTag);
44 $this->get('session')->getFlashBag()->add(
49 return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
52 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', array(
53 'form' => $form->createView(),
59 * Removes tag from entry.
61 * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
63 * @return \Symfony\Component\HttpFoundation\Response
65 public function removeTagFromEntry(Request
$request, Entry
$entry, Tag
$tag)
67 $entry->removeTag($tag);
68 $em = $this->getDoctrine()->getManager();
70 if (count($tag->getEntries()) == 0) {
75 return $this->redirect($request->headers
->get('referer'));
79 * Shows tags for current user.
81 * @Route("/tag/list", name="tag")
83 * @return \Symfony\Component\HttpFoundation\Response
85 public function showTagAction()
87 $tags = $this->getDoctrine()
88 ->getRepository('WallabagCoreBundle:Tag')
89 ->findTags($this->getUser()->getId());
92 'WallabagCoreBundle:Tag:tags.html.twig',