66 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\BudgetBundle\Templating;
use Chill\BudgetBundle\Config\ConfigRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use UnexpectedValueException;
class Twig extends AbstractExtension
{
/**
* @var ConfigRepository
*/
protected $configRepository;
/**
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
public function __construct(
ConfigRepository $configRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->configRepository = $configRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function displayLink($link, $family)
{
switch ($family) {
case 'resource':
return $this->translatableStringHelper->localize(
$this->configRepository->getResourcesLabels()[$link]
);
case 'charge':
return $this->translatableStringHelper->localize(
$this->configRepository->getChargesLabels()[$link]
);
default:
throw new UnexpectedValueException("This family of element: {$family} is not "
. "supported. Supported families are 'resource', 'charge'");
}
}
public function getFilters()
{
return [
new TwigFilter('budget_element_type_display', [$this, 'displayLink'], ['is_safe' => ['html']]),
];
}
}