aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/EntryController.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-06-02 18:54:34 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-06-02 18:56:07 +0200
commit82d6d9cb06a1486e2e3b05fa6ce857b3b8655180 (patch)
tree973017b934f12bed3a46cc23b30446a41c9ff7d8 /src/Wallabag/CoreBundle/Controller/EntryController.php
parent51d9699fa130a18a1c5cd09d1b03a382d73e91db (diff)
downloadwallabag-82d6d9cb06a1486e2e3b05fa6ce857b3b8655180.tar.gz
wallabag-82d6d9cb06a1486e2e3b05fa6ce857b3b8655180.tar.zst
wallabag-82d6d9cb06a1486e2e3b05fa6ce857b3b8655180.zip
Add basic title edition
Fix #218 I mean basic, because there is no javascript at all. It could be a nice edit-in-place. But for the moment, it is simple.
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 7fd982c9..4a7a0644 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -7,7 +7,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Service\Extractor; 9use Wallabag\CoreBundle\Service\Extractor;
10use Wallabag\CoreBundle\Form\Type\EntryType; 10use Wallabag\CoreBundle\Form\Type\NewEntryType;
11use Wallabag\CoreBundle\Form\Type\EditEntryType;
11 12
12class EntryController extends Controller 13class EntryController extends Controller
13{ 14{
@@ -22,7 +23,7 @@ class EntryController extends Controller
22 { 23 {
23 $entry = new Entry($this->getUser()); 24 $entry = new Entry($this->getUser());
24 25
25 $form = $this->createForm(new EntryType(), $entry); 26 $form = $this->createForm(new NewEntryType(), $entry);
26 27
27 $form->handleRequest($request); 28 $form->handleRequest($request);
28 29
@@ -50,6 +51,42 @@ class EntryController extends Controller
50 } 51 }
51 52
52 /** 53 /**
54 * Edit an entry content.
55 *
56 * @param Request $request
57 * @param Entry $entry
58 *
59 * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit")
60 *
61 * @return \Symfony\Component\HttpFoundation\Response
62 */
63 public function editEntryAction(Request $request, Entry $entry)
64 {
65 $this->checkUserAction($entry);
66
67 $form = $this->createForm(new EditEntryType(), $entry);
68
69 $form->handleRequest($request);
70
71 if ($form->isValid()) {
72 $em = $this->getDoctrine()->getManager();
73 $em->persist($entry);
74 $em->flush();
75
76 $this->get('session')->getFlashBag()->add(
77 'notice',
78 'Entry updated'
79 );
80
81 return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
82 }
83
84 return $this->render('WallabagCoreBundle:Entry:edit.html.twig', array(
85 'form' => $form->createView(),
86 ));
87 }
88
89 /**
53 * Shows unread entries for current user. 90 * Shows unread entries for current user.
54 * 91 *
55 * @Route("/unread", name="unread") 92 * @Route("/unread", name="unread")
@@ -212,7 +249,7 @@ class EntryController extends Controller
212 private function checkUserAction(Entry $entry) 249 private function checkUserAction(Entry $entry)
213 { 250 {
214 if ($this->getUser()->getId() != $entry->getUser()->getId()) { 251 if ($this->getUser()->getId() != $entry->getUser()->getId()) {
215 throw $this->createAccessDeniedException('You can not use this entry.'); 252 throw $this->createAccessDeniedException('You can not access this entry.');
216 } 253 }
217 } 254 }
218} 255}