diff --git a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Controller/PagerfantaController.php b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Controller/PagerfantaController.php index b0621b8..aab8284 100644 --- a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Controller/PagerfantaController.php +++ b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Controller/PagerfantaController.php @@ -29,6 +29,11 @@ public function viewWithOptionsAction() return $this->renderPagerfanta('viewWithOptions'); } + public function viewWithFirstPageParamAction(Request $request) + { + return $this->defaultWithRequestAction($request, 'viewWithFirstPageParam'); + } + public function defaultTranslatedViewAction() { return $this->renderPagerfanta('defaultTranslatedView'); @@ -54,9 +59,9 @@ public function viewWithRouteParamsAction($test = null) return $this->renderPagerfanta('viewWithRouteParams'); } - public function defaultWithRequestAction(Request $request) + public function defaultWithRequestAction(Request $request, $name = 'defaultView') { - $template = $this->buildTemplateName('defaultView'); + $template = $this->buildTemplateName($name); $pagerfanta = $this->createPagerfanta(); $pagerfanta->setMaxPerPage($request->query->get('maxPerPage', 10)); $pagerfanta->setCurrentPage($request->query->get('currentPage', 1)); diff --git a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/config/routing.yml b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/config/routing.yml index 292c2cc..5664fcb 100644 --- a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/config/routing.yml +++ b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/config/routing.yml @@ -38,3 +38,7 @@ pagerfanta_my_view_1: pagerfanta_correct_view: path: /pagerfanta/custom-page defaults: { _controller: WhiteOctoberPagerfantaTestBundle:Pagerfanta:defaultWithRequest } + +pagerfanta_view_with_first_page_param: + path: /pagerfanta/view-with-first-page-param + defaults: { _controller: WhiteOctoberPagerfantaTestBundle:Pagerfanta:viewWithFirstPageParam } diff --git a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/views/Pagerfanta/viewWithFirstPageParam.html.twig b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/views/Pagerfanta/viewWithFirstPageParam.html.twig new file mode 100644 index 0000000..6f2dce4 --- /dev/null +++ b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Resources/views/Pagerfanta/viewWithFirstPageParam.html.twig @@ -0,0 +1 @@ +{{ pagerfanta(pagerfanta, 'default', {'omitFirstPage': false}) }} \ No newline at end of file diff --git a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Tests/Controller/PagerfantaControllerTest.php b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Tests/Controller/PagerfantaControllerTest.php index 600a1c7..bbb2042 100644 --- a/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Tests/Controller/PagerfantaControllerTest.php +++ b/TestsProject/src/WhiteOctober/PagerfantaTestBundle/Tests/Controller/PagerfantaControllerTest.php @@ -212,6 +212,27 @@ public function testFirstPageLinkDoesNotHaveParam() ); } + /** + * @test + */ + public function testFirstPageParam() + { + $this->assertView('view-with-first-page-param?currentPage=2', << + Previous + 1 + 2 + 3 + 4 + 5 + ... + 10 + Next + +EOF + ); + } + /** * @test */ diff --git a/Twig/PagerfantaExtension.php b/Twig/PagerfantaExtension.php index 67a1f02..2159284 100644 --- a/Twig/PagerfantaExtension.php +++ b/Twig/PagerfantaExtension.php @@ -103,6 +103,7 @@ private function createRouteGenerator($options = array()) 'routeName' => null, 'routeParams' => array(), 'pageParameter' => '[page]', + 'omitFirstPage' => true ), $options); $router = $this->container->get('router'); @@ -133,13 +134,15 @@ private function createRouteGenerator($options = array()) $routeName = $options['routeName']; $routeParams = $options['routeParams']; $pagePropertyPath = new PropertyPath($options['pageParameter']); + $omitFirstPage = $options['omitFirstPage']; - return function($page) use($router, $routeName, $routeParams, $pagePropertyPath) { + return function($page) use($router, $routeName, $routeParams, $pagePropertyPath, $omitFirstPage) { $propertyAccessor = PropertyAccess::createPropertyAccessor(); - $propertyAccessor->setValue($routeParams, $pagePropertyPath, $page); - - $pageParam = $page > 1 ? $page : null; - $propertyAccessor->setValue($routeParams, $pagePropertyPath, $pageParam); + if($omitFirstPage){ + $propertyAccessor->setValue($routeParams, $pagePropertyPath, $page > 1 ? $page : null); + } else { + $propertyAccessor->setValue($routeParams, $pagePropertyPath, $page); + } return $router->generate($routeName, $routeParams); };