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)
24 $form = $this->createForm(new NewTagType(), $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 * Shows tags for current user.
61 * @Route("/tag/list", name="tag")
63 * @return \Symfony\Component\HttpFoundation\Response
65 public function showTagAction()
67 $tags = $this->getDoctrine()
68 ->getRepository('WallabagCoreBundle:Tag')
69 ->findTags($this->getUser()->getId());
72 'WallabagCoreBundle:Tag:tags.html.twig',