- 🇮🇱Israel jkdev
Just override the parameter from your own
ServiceProvider
.Instead of using symfony magic and replace the way the container is being built, use the drupal/symfony way to alter services/parameters in the container:
https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio... →In essence what we did is to create file: my_module/src/MyModuleServiceProvider.php (the name matters) looks like this:
namespace Drupal\my_module; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderBase; class MyModuleServiceProvider extends ServiceProviderBase { /** * {@inheritdoc} */ public function alter(ContainerBuilder $container) { $cors_config = $container->getParameter('cors.config'); $cors_config['allowedOrigins'] = ['https://' . $_ENV['CONSUMER_HOST']]; $container->setParameter('cors.config', $cors_config); } }
Make sure clear cache (so container will be compiled fresh) -
drush cr
/drush cc container
- First commit to issue fork.
@bircher
I added some basic test coverage for resolving the env variable at compile time.I'm also playing around with the idea to support using environment variables during runtime, see the --runtime branch.
This is clearly a bit more involved, and I think belongs really into its own issue in the first place.- 🇧🇪Belgium dieterholvoet Brussels
@jkdev by doing it that way the values from environment variables are cached in the container, which means you need to rebuild caches anytime an environment variable is changed. I don't think we want that.
@duadua looks like you haven't pushed anything yet to the
issue-3249970--runtime
and3249970-support-setting-service
branches. I'm not sure why, but it contains some commits from other issues. Onlyissue-3249970
contains relevant commits. - 🇧🇪Belgium mr.baileys 🇧🇪 (Ghent)
mr.baileys → changed the visibility of the branch issue-3249970--runtime to hidden.
- 🇧🇪Belgium mr.baileys 🇧🇪 (Ghent)
mr.baileys → changed the visibility of the branch 3249970-support-setting-service to hidden.
- Merge request !9628Draft: Issue 3249970: Support setting service parameters via environment variables → (Open) created by mr.baileys
- 🇧🇪Belgium mr.baileys 🇧🇪 (Ghent)
- Created a new branch issue-3249970-11x, cherry-picked the commits from @duadua and brought it up to date with 11.x;
- Fixed PHPCS violations;
- Tested with setting an environment variable via ddev/config.yaml, verifying it is used after this patch is applied;
The Needs Review Queue Bot → tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.