From 82d6d9cb06a1486e2e3b05fa6ce857b3b8655180 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 2 Jun 2015 18:54:34 +0200 Subject: 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. --- .../CoreBundle/Controller/EntryController.php | 43 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller') 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; use Symfony\Component\HttpFoundation\Request; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Service\Extractor; -use Wallabag\CoreBundle\Form\Type\EntryType; +use Wallabag\CoreBundle\Form\Type\NewEntryType; +use Wallabag\CoreBundle\Form\Type\EditEntryType; class EntryController extends Controller { @@ -22,7 +23,7 @@ class EntryController extends Controller { $entry = new Entry($this->getUser()); - $form = $this->createForm(new EntryType(), $entry); + $form = $this->createForm(new NewEntryType(), $entry); $form->handleRequest($request); @@ -49,6 +50,42 @@ class EntryController extends Controller )); } + /** + * Edit an entry content. + * + * @param Request $request + * @param Entry $entry + * + * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function editEntryAction(Request $request, Entry $entry) + { + $this->checkUserAction($entry); + + $form = $this->createForm(new EditEntryType(), $entry); + + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Entry updated' + ); + + return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); + } + + return $this->render('WallabagCoreBundle:Entry:edit.html.twig', array( + 'form' => $form->createView(), + )); + } + /** * Shows unread entries for current user. * @@ -212,7 +249,7 @@ class EntryController extends Controller private function checkUserAction(Entry $entry) { if ($this->getUser()->getId() != $entry->getUser()->getId()) { - throw $this->createAccessDeniedException('You can not use this entry.'); + throw $this->createAccessDeniedException('You can not access this entry.'); } } } -- cgit v1.2.3