From 7781faa0b0749b0d9842fddec3e337db04d44a10 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 16 Feb 2015 21:31:42 +0100 Subject: [PATCH] Use a form type for entry --- .../CoreBundle/Controller/EntryController.php | 7 ++--- .../CoreBundle/Form/Type/EntryType.php | 29 +++++++++++++++++++ .../Tests/Controller/EntryControllerTest.php | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Form/Type/EntryType.php diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 89677bef..81ab7788 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -7,7 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Service\Extractor; -use Wallabag\CoreBundle\Helper\Url; +use Wallabag\CoreBundle\Form\Type\EntryType; class EntryController extends Controller { @@ -22,10 +22,7 @@ class EntryController extends Controller { $entry = new Entry($this->getUser()); - $form = $this->createFormBuilder($entry) - ->add('url', 'url') - ->add('save', 'submit') - ->getForm(); + $form = $this->createForm(new EntryType(), $entry); $form->handleRequest($request); diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryType.php b/src/Wallabag/CoreBundle/Form/Type/EntryType.php new file mode 100644 index 00000000..cfd64473 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/EntryType.php @@ -0,0 +1,29 @@ +add('url', 'url') + ->add('save', 'submit') + ; + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Wallabag\CoreBundle\Entity\Entry', + )); + } + + public function getName() + { + return 'entry'; + } +} diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 7276f8e4..2634141e 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -60,7 +60,7 @@ class EntryControllerTest extends WallabagTestCase $form = $crawler->filter('button[type=submit]')->form(); $data = array( - 'form[url]' => 'https://www.mailjet.com/blog/mailjet-zapier-integrations-made-easy/', + 'entry[url]' => 'https://www.mailjet.com/blog/mailjet-zapier-integrations-made-easy/', ); $client->submit($form, $data); -- 2.41.0