1

I'm creating reusable Symfony bundle that has many configuration parameters and I need them in framework and twig bundles also.

Here is a working example of how my config currently looks (app/config/config.yml):

# my bundle parameters
parameters:
  locales_active:
    - en_US
    - de_DE
  locale_default: en_US
  locale_fallback: de_DE
  google_maps_api_key: some_value
  google_translate_api_key: some_value

# framework parameters
framework:
  translator:      { fallbacks: ['%locale_fallback%']
  default_locale:  "%locale_default%"

# twig parameters
twig:
  globals:
    locales_active: '%locales_active%'
    google_maps_api_key: '%google_maps_api_key%'
    google_translate_api_key: '%google_translate_api_key%'

This approach works, but I want to be as simple as possible to install this bundle (here is only a small part of parameters, actually there are many more).

What I would like to do is:

1) only create this part of code in config.yml (move bundle parameters to it's own namespace from global "parameters:"):

acme_core:
  locales_active:
    - en_US
    - de_DE
  locale_default: en_US
  locale_fallback: de_DE
  google_maps_api_key: some_value
  google_translate_api_key: some_value

2) assign these parameters to framework or twig dynamically without editing configuration file. For example, maybe in DependencyInjection/Configuration.php if that is possible.

How this could be achieved?

0

1 Answer 1

0

It's easy to achieve. Just play around with it.

You need to use DependencyInjection/Configuration and AcmeCoreExtension.

  1. Configuration file should contain validation params and the structure of your bundle's configuration.
  2. AcmeCoreExtension should merge your config with twig.
public function load(array $configs, ContainerBuilder $container)
{
    $configuration = new Configuration();

    $config = $this->processConfiguration($configuration, $configs);

    // merge your configs here (or something similar)
    // $config['twig']['globals']['locales_active'] = 
}

http://symfony.com/doc/current/bundles/configuration.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.