router = $router; } /** * {@inheritdoc} */ public function getFunctions() { return [ new TwigFunction('pagerfanta', [$this, 'renderPagerfanta'], ['is_safe' => ['html']]), new TwigFunction('pagination', [$this, 'renderPagination'], ['is_safe' => ['html']]), ]; } private function getView(): ViewInterface { if (null === $this->view) { $this->view = new TwitterBootstrap3View(); } return $this->view; } /** * @deprecated since 1.8 */ public function renderPagerfanta(Pagerfanta $pagerfanta, $viewName = null, array $options = []) { @trigger_error('Twig function pagerfanta() is deprecated and will be removed with 2.0, use pagination() instead', E_USER_DEPRECATED); if (\is_array($viewName)) { $options = $viewName; } return $this->renderPagination($pagerfanta, $options); } public function renderPagination(Pagerfanta $pagerfanta, array $options = []) { $routeGenerator = $this->createRouteGenerator($options); $options['proximity'] = 1; //$options['prev_message'] = '←'; //$options['next_message'] = '→'; $options['prev_message'] = ''; $options['next_message'] = ''; return $this->getView()->render($pagerfanta, $routeGenerator, $options); } private function createRouteGenerator(array $options = []) { $options = array_replace([ 'routeName' => null, 'routeParams' => [], 'pageParameter' => '[page]', ], $options); $router = $this->router; if (null === $options['routeName']) { throw new \Exception('Pagination is missing the "routeName" option'); } $routeName = $options['routeName']; $routeParams = $options['routeParams']; $pagePropertyPath = new PropertyPath($options['pageParameter']); return function ($page) use ($router, $routeName, $routeParams, $pagePropertyPath) { $propertyAccessor = PropertyAccess::createPropertyAccessor(); $propertyAccessor->setValue($routeParams, $pagePropertyPath, $page); return $router->generate($routeName, $routeParams); }; } }