forms icon indicating copy to clipboard operation
forms copied to clipboard

Symfony config parameters cannot be used in form configuration

Open benr77 opened this issue 3 years ago • 4 comments

Bolt Forms 1.4.17

I'm using the reCaptcha v3 field type and need to specify the Google API keys. Currently it seems that you cannot use any Symfony configuration parameters or environment variables in this config file, like you can with Symfony YAML configuration, so I'm forced to hard-code the API keys, meaning they get stored in the Git repo and are visible to all.

Is this a known limitation?

Thanks

benr77 avatar Apr 04 '22 13:04 benr77

Hello, Symfony uses a compiler pass (ResolveParameterPlaceHoldersPass()) for parsing parameters placeholders and replace them with actual values. As far I know, Bolt Forms doesn't store his configurations in Symfony's container at all. It's YAML parser is a simple service, injected in every place the configuration is needed, and the YAML files are parsed on demand. Conclusion : no use of container = no compiler pass = no placeholders params replacement.

david-saisondor avatar Apr 22 '22 08:04 david-saisondor

Thanks for your reply. I can see what you are referring to.

This does seem rather strange to me, as Bolt is based on Symfony, and yet has rolled it's own configuration reading instead of just using the default Symfony config system.

As a consequence, I have to hard-code API keys into files instead of using environment variables or even the Symfony Secrets system.

Bolt Forms could be a Symfony bundle, and have a standard bundle configuration file. I don't know the reasoning behind why this is not the case, but I'm guessing @bobdenotter will be able to shed some light on this.

benr77 avatar Apr 22 '22 08:04 benr77

I encounter the same problem as you : I have 4 forms with ReCaptcha, and I have to centralize Google keys. I've not tested it yet, but there is a possible solution :

  1. Write you keys in .env.local or the server environment vars
  2. In service.yaml, define a couple of parameters based on two previous var params
  3. In YAML forms config, use dummy params for ReCaptcha keys
  4. In your own implementation of @boltforms/form.twig, use the configuration overrides capabilities of boltforms() Twig function, to pass the keys to the ReCaptcha fields, since Twig has access to the params container.
  5. Take a well deserved rest.

david-saisondor avatar Apr 22 '22 08:04 david-saisondor

Aha that looks interesting (the config overrides) - thanks. I'll give that a try when I'm next back on that project.

benr77 avatar Apr 22 '22 09:04 benr77