2021-11-30 13:54:58 +01:00

72 lines
1.6 KiB
PHP

<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Pagination;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* add twig function to render pagination.
*/
class ChillPaginationTwig extends AbstractExtension
{
public const LONG_TEMPLATE = '@ChillMain/Pagination/long.html.twig';
public const SHORT_TEMPLATE = '@ChillMain/Pagination/short.html.twig';
public function getFunctions()
{
return [
new TwigFunction(
'chill_pagination',
[$this, 'paginationRender'],
[
'needs_environment' => true,
'is_safe' => ['html'],
]
),
];
}
public function getName()
{
return 'chill_pagination';
}
public function paginationRender(
Environment $env,
PaginatorInterface $paginator,
$template = '@ChillMain/Pagination/long.html.twig'
) {
switch ($template) {
case 'long':
$t = self::LONG_TEMPLATE;
break;
case 'short':
$t = self::SHORT_TEMPLATE;
break;
default:
$t = $template;
}
return $env->render($t, [
'paginator' => $paginator,
'current' => $paginator->getCurrentPage()->getNumber(),
]);
}
}