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\Form\Type\NewTagType
;
9 use Wallabag\CoreBundle\Entity\Tag
;
10 use Wallabag\CoreBundle\Entity\Entry
;
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)
23 $tag = new Tag($this->getUser());
24 $form = $this->createForm(new NewTagType(), $tag);
25 $form->handleRequest($request);
27 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine()
29 ->getRepository('WallabagCoreBundle:Tag')
30 ->findOneByLabelAndUserId($tag->getLabel(), $this->getUser()->getId());
32 $em = $this->getDoctrine()->getManager();
34 if (is_null($existingTag)) {
38 if (!$existingTag->hasEntry($entry)) {
39 $entry->addTag($existingTag);
40 $em->persist($existingTag);
46 $this->get('session')->getFlashBag()->add(
51 return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
54 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', array(
55 'form' => $form->createView(),
61 * Shows tags for current user.
63 * @Route("/tag/list", name="tag")
65 * @return \Symfony\Component\HttpFoundation\Response
67 public function showTagAction()
69 $tags = $this->getDoctrine()
70 ->getRepository('WallabagCoreBundle:Tag')
71 ->findTags($this->getUser()->getId());
74 'WallabagCoreBundle:Tag:tags.html.twig',