From 1d76102a240c2596832848128a7b9cf5aa2050dd Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 9 Jan 2016 18:38:40 +0100 Subject: Fix recent update - some missing url parameters from WallabagRestController & EntryController - use a service for `EntryFilterType` to use fully qualified name instead (so changing class signature) - update ImportBundle (url & form) --- .../ApiBundle/Controller/WallabagRestController.php | 3 ++- .../CoreBundle/Controller/EntryController.php | 2 +- src/Wallabag/CoreBundle/Filter/EntryFilterType.php | 20 ++++++++++---------- .../CoreBundle/Form/Type/UserInformationType.php | 2 +- .../CoreBundle/Resources/config/services.yml | 8 ++++++++ .../ImportBundle/Controller/PocketController.php | 5 +++-- .../ImportBundle/Controller/WallabagV1Controller.php | 2 +- .../ImportBundle/Form/Type/UploadImportType.php | 8 +++++--- 8 files changed, 31 insertions(+), 19 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index f8a2745a..d9035cac 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -8,6 +8,7 @@ use Hateoas\Representation\Factory\PagerfantaFactory; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; @@ -84,7 +85,7 @@ class WallabagRestController extends FOSRestController $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); $paginatedCollection = $pagerfantaFactory->createRepresentation( $pager, - new Route('api_get_entries', [], $absolute = true) + new Route('api_get_entries', [], UrlGeneratorInterface::ABSOLUTE_URL) ); $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 83e5b57d..dda0a456 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -234,7 +234,7 @@ class EntryController extends Controller throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); } - $form = $this->createForm(new EntryFilterType($repository, $this->getUser())); + $form = $this->createForm(EntryFilterType::class); if ($request->query->has($form->getName())) { // manually bind values from the request diff --git a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php index 4430c971..c38be832 100644 --- a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php @@ -12,7 +12,7 @@ use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Wallabag\UserBundle\Entity\User; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; class EntryFilterType extends AbstractType { @@ -23,12 +23,12 @@ class EntryFilterType extends AbstractType * Repository & user are used to get a list of language entries for this user. * * @param EntityRepository $entryRepository - * @param User $user + * @param TokenStorage $token */ - public function __construct(EntityRepository $entryRepository, User $user) + public function __construct(EntityRepository $entryRepository, TokenStorage $token) { $this->repository = $entryRepository; - $this->user = $user; + $this->user = $token->getToken()->getUser(); } public function buildForm(FormBuilderInterface $builder, array $options) @@ -54,13 +54,13 @@ class EntryFilterType extends AbstractType ) ->add('domainName', TextFilterType::class, array( 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { - $value = $values['value']; - if (strlen($value) <= 2 || empty($value)) { - return; - } - $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); + $value = $values['value']; + if (strlen($value) <= 2 || empty($value)) { + return; + } + $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); - return $filterQuery->createCondition($expression); + return $filterQuery->createCondition($expression); }, )) ->add('isArchived', CheckboxFilterType::class) diff --git a/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php index f52e409a..f491b0ae 100644 --- a/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php +++ b/src/Wallabag/CoreBundle/Form/Type/UserInformationType.php @@ -26,7 +26,7 @@ class UserInformationType extends AbstractType public function getParent() { - return 'fos_user_registration'; + return 'FOS\UserBundle\Form\Type\RegistrationFormType'; } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index e8dafc5d..43600735 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -14,6 +14,14 @@ services: tags: - { name: form.type } + wallabag_core.filter.type.entry: + class: Wallabag\CoreBundle\Filter\EntryFilterType + arguments: + - "@wallabag_core.entry_repository" + - "@security.token_storage" + tags: + - { name: form.type } + wallabag_core.param_converter.username_rsstoken_converter: class: Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter tags: diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index a0853383..72dc2696 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -3,6 +3,7 @@ namespace Wallabag\ImportBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class PocketController extends Controller @@ -23,12 +24,12 @@ class PocketController extends Controller public function authAction() { $requestToken = $this->get('wallabag_import.pocket.import') - ->getRequestToken($this->generateUrl('import', [], true)); + ->getRequestToken($this->generateUrl('import', UrlGeneratorInterface::ABSOLUTE_URL)); $this->get('session')->set('import.pocket.code', $requestToken); return $this->redirect( - 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], true), + 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', UrlGeneratorInterface::ABSOLUTE_URL), 301 ); } diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php index e50a6c35..35fe620f 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php @@ -14,7 +14,7 @@ class WallabagV1Controller extends Controller */ public function indexAction(Request $request) { - $form = $this->createForm(new UploadImportType()); + $form = $this->createForm(UploadImportType::class); $form->handleRequest($request); $wallabag = $this->get('wallabag_import.wallabag_v1.import'); diff --git a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php index 415890f3..2e6b59cb 100644 --- a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php +++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php @@ -4,18 +4,20 @@ namespace Wallabag\ImportBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\FileType; class UploadImportType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('file', 'file') - ->add('save', 'submit') + ->add('file', FileType::class) + ->add('save', SubmitType::class) ; } - public function getName() + public function getBlockPrefix() { return 'upload_import_file'; } -- cgit v1.2.3