| 1 | <?php |
||
| 14 | class PaginationExtension extends \Twig_Extension |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $template = ''; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $template |
||
| 23 | */ |
||
| 24 | 5 | public function __construct($template) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @return array |
||
| 31 | */ |
||
| 32 | 1 | public function getFunctions() |
|
| 33 | { |
||
| 34 | return [ |
||
| 35 | 1 | new \Twig_SimpleFunction( |
|
| 36 | 1 | 'pagination_render', |
|
| 37 | 1 | [$this, 'renderPagination'], |
|
| 38 | 1 | ['is_safe' => ['html'], 'needs_environment' => true] |
|
| 39 | 1 | ), |
|
| 40 | 1 | ]; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param \Twig_Environment $env |
||
| 45 | * @param Configuration $pagination |
||
| 46 | * @param string $template |
||
| 47 | * @param array $view_params |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | 3 | public function renderPagination( |
|
| 52 | \Twig_Environment $env, |
||
| 53 | Configuration $pagination, |
||
| 54 | $template = null, |
||
| 55 | array $view_params = [] |
||
| 56 | ) { |
||
| 57 | 3 | return $env->render( |
|
| 58 | 3 | $template ?: $this->template, |
|
| 59 | 3 | array_merge( |
|
| 60 | 3 | $view_params, |
|
| 61 | 3 | ['pagination' => $pagination->getView()] |
|
| 62 | 3 | ) |
|
| 63 | 3 | ); |
|
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 1 | public function getName() |
|
| 73 | } |
||
| 74 |