X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FTagController.php;h=8a0932892d58567f94b3d46956be208d9d48a867;hb=f17b89fadce0a8c2280fbe1518d66f20dddce59d;hp=1cbc413d644e616727ce0dca82af9b6f5582cd15;hpb=cdd3010b478c9ca818dd6d22d03c81ef4a5ab208;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 1cbc413d..8a093289 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -27,7 +27,7 @@ class TagController extends Controller $form = $this->createForm(NewTagType::class, new Tag()); $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->get('wallabag_core.content_proxy')->assignTagsToEntry( $entry, $form->get('label')->getData() @@ -63,10 +63,12 @@ class TagController extends Controller $entry->removeTag($tag); $em = $this->getDoctrine()->getManager(); $em->flush(); - if (count($tag->getEntries()) == 0) { + + // remove orphan tag in case no entries are associated to it + if (count($tag->getEntries()) === 0) { $em->remove($tag); + $em->flush(); } - $em->flush(); $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); @@ -86,12 +88,24 @@ class TagController extends Controller ->getRepository('WallabagCoreBundle:Tag') ->findAllTags($this->getUser()->getId()); - return $this->render( - 'WallabagCoreBundle:Tag:tags.html.twig', - [ - 'tags' => $tags, - ] - ); + $flatTags = []; + + foreach ($tags as $tag) { + $nbEntries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId()); + + $flatTags[] = [ + 'id' => $tag->getId(), + 'label' => $tag->getLabel(), + 'slug' => $tag->getSlug(), + 'nbEntries' => $nbEntries, + ]; + } + + return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ + 'tags' => $flatTags, + ]); } /** @@ -125,13 +139,11 @@ class TagController extends Controller } } - return $this->render( - 'WallabagCoreBundle:Entry:entries.html.twig', - [ - 'form' => null, - 'entries' => $entries, - 'currentPage' => $page, - ] - ); + return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [ + 'form' => null, + 'entries' => $entries, + 'currentPage' => $page, + 'tag' => $tag->getSlug(), + ]); } }