Use static message in settings to remove translation editor clutter

This commit is contained in:
Jan Böhmer 2025-11-30 15:17:37 +01:00
parent 5d843ec8eb
commit e112a8dbe0
2 changed files with 6 additions and 2 deletions

View file

@ -31,6 +31,7 @@ use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\Locales;
use Symfony\Component\Translation\StaticMessage;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -67,7 +68,9 @@ class TypeSynonymRowType extends AbstractType
new Assert\NotBlank(),
],
'choice_label' => function (ElementTypes $choice) {
return $this->translator->trans($choice->getDefaultLabelKey()) . ' (' . $this->translator->trans($choice->getDefaultPluralLabelKey()) . ')';
return new StaticMessage(
$this->translator->trans($choice->getDefaultLabelKey()) . ' (' . $this->translator->trans($choice->getDefaultPluralLabelKey()) . ')'
);
},
'row_attr' => ['class' => 'mb-0'],
'attr' => ['class' => 'form-select-sm'],

View file

@ -30,6 +30,7 @@ use Jbtronics\SettingsBundle\ParameterTypes\StringType;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\StaticMessage;
use Symfony\Component\Translation\TranslatableMessage as TM;
use Symfony\Component\Validator\Constraints as Assert;
@ -43,7 +44,7 @@ class IpnSuggestSettings
label: new TM("settings.misc.ipn_suggest.regex"),
description: new TM("settings.misc.ipn_suggest.regex.help"),
options: ['type' => StringType::class],
formOptions: ['attr' => ['placeholder' => '^[A-Za-z0-9]{3,4}(?:-[A-Za-z0-9]{3,4})*-\d{4}$']],
formOptions: ['attr' => ['placeholder' => new StaticMessage( '^[A-Za-z0-9]{3,4}(?:-[A-Za-z0-9]{3,4})*-\d{4}$')]],
envVar: "IPN_SUGGEST_REGEX", envVarMode: EnvVarMode::OVERWRITE,
)]
public ?string $regex = null;