3 namespace Wallabag\CoreBundle\Controller
;
5 use Pagerfanta\Adapter\ArrayAdapter
;
6 use Pagerfanta\Exception\OutOfRangeCurrentPageException
;
7 use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter
;
8 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
9 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
10 use Symfony\Component\HttpFoundation\Request
;
11 use Wallabag\CoreBundle\Entity\Entry
;
12 use Wallabag\CoreBundle\Entity\Tag
;
13 use Wallabag\CoreBundle\Form\Type\NewTagType
;
15 class TagController
extends Controller
18 * @param Request $request
21 * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag")
23 * @return \Symfony\Component\HttpFoundation\Response
25 public function addTagFormAction(Request
$request, Entry
$entry)
27 $form = $this->createForm(NewTagType
::class, new Tag());
28 $form->handleRequest($request);
30 if ($form->isSubmitted() && $form->isValid()) {
31 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
33 $form->get('label')->getData()
36 $em = $this->getDoctrine()->getManager();
40 $this->get('session')->getFlashBag()->add(
42 'flashes.tag.notice.tag_added'
45 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
48 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', [
49 'form' => $form->createView(),
55 * Removes tag from entry.
57 * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
59 * @return \Symfony\Component\HttpFoundation\Response
61 public function removeTagFromEntry(Request
$request, Entry
$entry, Tag
$tag)
63 $entry->removeTag($tag);
64 $em = $this->getDoctrine()->getManager();
67 // remove orphan tag in case no entries are associated to it
68 if (0 === \
count($tag->getEntries())) {
73 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers
->get('referer'), '', true);
75 return $this->redirect($redirectUrl);
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->get('wallabag_core.tag_repository')
88 ->findAllFlatTagsWithNbEntries($this->getUser()->getId());
90 return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
99 * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"})
100 * @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
102 * @return \Symfony\Component\HttpFoundation\Response
104 public function showEntriesForTagAction(Tag
$tag, $page, Request
$request)
106 $entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
107 $this->getUser()->getId(),
111 $pagerAdapter = new ArrayAdapter($entriesByTag);
113 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
116 $entries->setCurrentPage($page);
117 } catch (OutOfRangeCurrentPageException
$e) {
119 return $this->redirect($this->generateUrl($request->get('_route'), [
120 'slug' => $tag->getSlug(),
121 'page' => $entries->getNbPages(),
126 return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [
128 'entries' => $entries,
129 'currentPage' => $page,