aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-27 17:09:33 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-27 17:09:33 +0200
commit2baca964f38e658f60c8b9f81a9db289ba85bd0d (patch)
treef229054b676da315fba9e0ee35d90e838c5e37a5 /src/Wallabag/CoreBundle/Controller
parent5a4ee4ae0fe7bed85fc68a9e96aee8bf5d1ee782 (diff)
downloadwallabag-2baca964f38e658f60c8b9f81a9db289ba85bd0d.tar.gz
wallabag-2baca964f38e658f60c8b9f81a9db289ba85bd0d.tar.zst
wallabag-2baca964f38e658f60c8b9f81a9db289ba85bd0d.zip
Simplify tag creation from entry
Testing that a tag exist or is assigned to the current entry isn't important in the tag controler since the `assignTagsToEntry` is already doing that job. So it simplify the controller.
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index f31f4028..1a1f8c3d 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -20,31 +20,17 @@ class TagController extends Controller
20 */ 20 */
21 public function addTagFormAction(Request $request, Entry $entry) 21 public function addTagFormAction(Request $request, Entry $entry)
22 { 22 {
23 $tag = new Tag(); 23 $form = $this->createForm(NewTagType::class, new Tag());
24 $form = $this->createForm(NewTagType::class, $tag);
25 $form->handleRequest($request); 24 $form->handleRequest($request);
26 25
27 if ($form->isValid()) { 26 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine() 27 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
29 ->getRepository('WallabagCoreBundle:Tag') 28 $entry,
30 ->findOneByLabel($tag->getLabel()); 29 $form->get('label')->getData()
30 );
31 31
32 $em = $this->getDoctrine()->getManager(); 32 $em = $this->getDoctrine()->getManager();
33 33 $em->persist($entry);
34 if (is_null($existingTag)) {
35 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
36 $entry,
37 $tag
38 );
39 $em->persist($tag);
40 } elseif (!$existingTag->hasEntry($entry)) {
41 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
42 $entry,
43 $existingTag
44 );
45 $em->persist($existingTag);
46 }
47
48 $em->flush(); 34 $em->flush();
49 35
50 $this->get('session')->getFlashBag()->add( 36 $this->get('session')->getFlashBag()->add(