What is the purpose of the message parameters array in a Symfony form error ?
For example, I have the following case: on a form I have a subscriber in which, based on the information given by the user an API may be called and some additional errors could be added to the Symfony form.
As such, when an error occurs, I add a new error on a field:
$myForm->get('name')->addError(
new FormError('name.api_invalid', null, array('{{ api_name }}' => $someValue))
);
where 'name.api_invalid' is defined in message.en.yml as
name.api_invalid: "The API says the name is actually {{ api_name }}. Please fix before proceeding."
While the message is translated, the "parameters" are not replaced.
Is this not how form error parameters are supposed to work ?
Note: I can make it work by using
$myForm->get('name')->addError(
new FormError(
$this->translator->trans('name.api_invalid', array('{{ api_name }}' => $someValue))
)
);
but I'm really curious about those error parameters.
Thank you!
{{ api_name }}with%api_name%which better resembles Symfony convention and usage of parameters. The way you are using that translation message looks like a Twig variable when it's not.{{ api_name }}because this is also the way variables are used in the Symfony constraint messages (symfony.com/doc/current/reference/constraints/Length.html). Tried using % instead, but still no luck, Either way though, in the end this is just a token, so whatever syntax each dev prefers, it should work ... but it doesn't :)