/** * @param GetResponseForControllerResultEvent $event */ public function onKernelResponse(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); if ($request->isXmlHttpRequest() && ($result = $event->getControllerResult()) && !empty($result['pagination']) && $result['pagination'] instanceof SlidingPagination) { $result = array('items' => $result['pagination']->getItems(), 'pagination' => $result['pagination']->getPaginationData(), 'paginationHtml' => $this->paginationExtension->render($this->twig, $result['pagination'])); $json = $this->serializer->serialize($result, 'json'); $response = new Response($json, Response::HTTP_OK, ['Content-Type' => 'application/json']); $event->setResponse($response); } }
/** * {@inheritDoc} */ public function getFunctions() { return array_merge(parent::getFunctions(), [new \Twig_SimpleFunction('pagination', array($this, 'render'), array('is_safe' => array('html'), 'needs_environment' => true)), new \Twig_SimpleFunction('pagination_sortable', array($this, 'sortable'), array('is_safe' => array('html'), 'needs_environment' => true)), new \Twig_SimpleFunction('pagination_filter', array($this, 'filter'), array('is_safe' => array('html'), 'needs_environment' => true))]); }