]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Merge pull request #1471 from wallabag/v2-bookmarklet
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index b9e4e67e3b85561e11fdf0aee7316172204a984a..f7b52eaf71b4de811dedc7173d78eae51935d181 100644 (file)
@@ -14,6 +14,23 @@ use Pagerfanta\Pagerfanta;
 
 class EntryController extends Controller
 {
+    /**
+     * @param Entry $entry
+     */
+    private function updateEntry(Entry $entry)
+    {
+        try {
+            $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
+            $em = $this->getDoctrine()->getManager();
+            $em->persist($entry);
+            $em->flush();
+        } catch (\Exception $e) {
+            return false;
+        }
+
+        return true;
+    }
+
     /**
      * @param Request $request
      *
@@ -30,12 +47,7 @@ class EntryController extends Controller
         $form->handleRequest($request);
 
         if ($form->isValid()) {
-            $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
-
-            $em = $this->getDoctrine()->getManager();
-            $em->persist($entry);
-            $em->flush();
-
+            $this->updateEntry($entry);
             $this->get('session')->getFlashBag()->add(
                 'notice',
                 'Entry saved'
@@ -49,6 +61,22 @@ class EntryController extends Controller
         ));
     }
 
+    /**
+     * @param Request $request
+     *
+     * @Route("/bookmarklet", name="bookmarklet")
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function addEntryViaBookmarklet(Request $request)
+    {
+        $entry = new Entry($this->getUser());
+        $entry->setUrl($request->get('url'));
+        $this->updateEntry($entry);
+
+        return $this->redirect($this->generateUrl('homepage'));
+    }
+
     /**
      * @param Request $request
      *
@@ -192,7 +220,7 @@ class EntryController extends Controller
                 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
         }
 
-        $form = $this->get('form.factory')->create(new EntryFilterType());
+        $form = $this->get('form.factory')->create(new EntryFilterType($repository, $this->getUser()));
 
         if ($request->query->has($form->getName())) {
             // manually bind values from the request