diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 7b34939d..1a1f8c3d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -20,30 +20,22 @@ 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 | $entry->addTag($tag); | ||
36 | $em->persist($tag); | ||
37 | } elseif (!$existingTag->hasEntry($entry)) { | ||
38 | $entry->addTag($existingTag); | ||
39 | $em->persist($existingTag); | ||
40 | } | ||
41 | |||
42 | $em->flush(); | 34 | $em->flush(); |
43 | 35 | ||
44 | $this->get('session')->getFlashBag()->add( | 36 | $this->get('session')->getFlashBag()->add( |
45 | 'notice', | 37 | 'notice', |
46 | 'Tag added' | 38 | 'flashes.tag.notice.tag_added' |
47 | ); | 39 | ); |
48 | 40 | ||
49 | return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); | 41 | return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); |