Support translatable labels in FilterOrderHelper and FilterOrderHelperBuilder

- Updated methods to accept `string|TranslatableInterface` for label parameters, allowing translation capabilities.
- Added `Symfony\Contracts\Translation\TranslatableInterface` imports in both classes.
This commit is contained in:
2026-02-16 13:30:07 +01:00
parent 22ace0c66e
commit cc769fd4ba
2 changed files with 10 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatableInterface;
final class FilterOrderHelper
{
@@ -53,7 +54,7 @@ final class FilterOrderHelper
private readonly RequestStack $requestStack,
) {}
public function addSingleCheckbox(string $name, string $label): self
public function addSingleCheckbox(string $name, string|TranslatableInterface $label): self
{
$this->singleCheckbox[$name] = ['label' => $label];
@@ -63,7 +64,7 @@ final class FilterOrderHelper
/**
* @param class-string $class
*/
public function addEntityChoice(string $name, string $class, string $label, array $choices, array $options = []): self
public function addEntityChoice(string $name, string $class, string|TranslatableInterface $label, array $choices, array $options = []): self
{
$this->entityChoices[$name] = ['label' => $label, 'class' => $class, 'choices' => $choices, 'options' => $options];
@@ -75,7 +76,7 @@ final class FilterOrderHelper
return $this->entityChoices;
}
public function addUserPicker(string $name, ?string $label = null, array $options = []): self
public function addUserPicker(string $name, string|TranslatableInterface|null $label = null, array $options = []): self
{
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
@@ -98,7 +99,7 @@ final class FilterOrderHelper
return $this;
}
public function addDateRange(string $name, ?string $label = null, ?\DateTimeImmutable $from = null, ?\DateTimeImmutable $to = null): self
public function addDateRange(string $name, string|TranslatableInterface|null $label = null, ?\DateTimeImmutable $from = null, ?\DateTimeImmutable $to = null): self
{
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];

View File

@@ -13,6 +13,7 @@ namespace Chill\MainBundle\Templating\Listing;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatableInterface;
class FilterOrderHelperBuilder
{
@@ -39,7 +40,7 @@ class FilterOrderHelperBuilder
public function __construct(private readonly FormFactoryInterface $formFactory, private readonly RequestStack $requestStack) {}
public function addSingleCheckbox(string $name, string $label): self
public function addSingleCheckbox(string $name, string|TranslatableInterface $label): self
{
$this->singleCheckboxes[$name] = ['label' => $label];
@@ -56,14 +57,14 @@ class FilterOrderHelperBuilder
/**
* @param class-string $class
*/
public function addEntityChoice(string $name, string $label, string $class, array $choices, ?array $options = []): self
public function addEntityChoice(string $name, string|TranslatableInterface $label, string $class, array $choices, ?array $options = []): self
{
$this->entityChoices[$name] = ['label' => $label, 'class' => $class, 'choices' => $choices, 'options' => $options];
return $this;
}
public function addDateRange(string $name, ?string $label = null, ?\DateTimeImmutable $from = null, ?\DateTimeImmutable $to = null): self
public function addDateRange(string $name, string|TranslatableInterface|null $label = null, ?\DateTimeImmutable $from = null, ?\DateTimeImmutable $to = null): self
{
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
@@ -77,7 +78,7 @@ class FilterOrderHelperBuilder
return $this;
}
public function addUserPicker(string $name, ?string $label = null, ?array $options = []): self
public function addUserPicker(string $name, string|TranslatableInterface|null $label = null, ?array $options = []): self
{
$this->userPickers[$name] = ['label' => $label, 'options' => $options];