Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony config parameters cannot be used in form configuration #99

Open
benr77 opened this issue Apr 4, 2022 · 4 comments
Open

Symfony config parameters cannot be used in form configuration #99

benr77 opened this issue Apr 4, 2022 · 4 comments

Comments

@benr77
Copy link

benr77 commented Apr 4, 2022

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

@david-saisondor
Copy link

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.

@benr77
Copy link
Author

benr77 commented Apr 22, 2022

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.

@david-saisondor
Copy link

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.

@benr77
Copy link
Author

benr77 commented Apr 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants