mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 23:32:17 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -19,6 +19,7 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormRenderer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Contracts\Translation\TranslatableInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
@@ -35,7 +36,7 @@ final class FormExtension extends AbstractExtension
|
||||
{
|
||||
private ?TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator = null)
|
||||
public function __construct(?TranslatorInterface $translator = null)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
@@ -149,23 +150,26 @@ final class FormExtension extends AbstractExtension
|
||||
private function createFieldChoicesList(iterable $choices, string|false|null $translationDomain): iterable
|
||||
{
|
||||
foreach ($choices as $choice) {
|
||||
$translatableLabel = $this->createFieldTranslation($choice->label, [], $translationDomain);
|
||||
|
||||
if ($choice instanceof ChoiceGroupView) {
|
||||
$translatableLabel = $this->createFieldTranslation($choice->label, [], $translationDomain);
|
||||
yield $translatableLabel => $this->createFieldChoicesList($choice, $translationDomain);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* @var ChoiceView $choice */
|
||||
/** @var ChoiceView $choice */
|
||||
$translatableLabel = $this->createFieldTranslation($choice->label, $choice->labelTranslationParameters, $translationDomain);
|
||||
yield $translatableLabel => $choice->value;
|
||||
}
|
||||
}
|
||||
|
||||
private function createFieldTranslation(?string $value, array $parameters, string|false|null $domain): ?string
|
||||
private function createFieldTranslation(TranslatableInterface|string|null $value, array $parameters, string|false|null $domain): ?string
|
||||
{
|
||||
if (!$this->translator || !$value || false === $domain) {
|
||||
return $value;
|
||||
return null !== $value ? (string) $value : null;
|
||||
}
|
||||
if ($value instanceof TranslatableInterface) {
|
||||
return $value->trans($this->translator);
|
||||
}
|
||||
|
||||
return $this->translator->trans($value, $parameters, $domain);
|
||||
|
||||
Reference in New Issue
Block a user