@@ -35,36 +35,8 @@ Acme\ExampleBundle\AcmeExampleBundle::class => ['all' => true],
3535
3636To parse semantic configuration, create a ` Configuration ` class which extends ` Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration ` and then extend its ` generateScopeBaseNode() ` method:
3737
38- ``` php hl_lines="17"
39- <?php
40-
41- namespace Acme\ExampleBundle\DependencyInjection;
42-
43- use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
44- use Symfony\Component\Config\Definition\Builder\TreeBuilder;
45-
46- class Configuration extends SiteAccessConfiguration
47- {
48- public function getConfigTreeBuilder(): TreeBuilder
49- {
50- $treeBuilder = new TreeBuilder('acme_example');
51- $rootNode = $treeBuilder->getRootNode();
52-
53- // $systemNode is the root of SiteAccess-aware settings.
54- $systemNode = $this->generateScopeBaseNode($rootNode);
55- $systemNode
56- ->scalarNode('name')->isRequired()->end()
57- ->arrayNode('custom_setting')
58- ->children()
59- ->scalarNode('string')->end()
60- ->integerNode('number')->end()
61- ->booleanNode('enabled')->end()
62- ->end()
63- ->end();
64-
65- return $treeBuilder;
66- }
67- }
38+ ``` php hl_lines="16"
39+ [[= include_file('code_samples/multisite/siteaccess/Configuration.php') =]]
6840```
6941
7042!!! note
@@ -96,57 +68,14 @@ Semantic configuration must always be mapped to internal key/value settings with
9668You usually do it in the [service container](php_api.md#service-container) extension.
9769
9870` ` ` php
99- <?php
100-
101- namespace Acme\ExampleBundle\DependencyInjection;
102-
103- use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
104- use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
105- use Symfony\Component\Config\FileLocator;
106- use Symfony\Component\DependencyInjection\ContainerBuilder;
107- use Symfony\Component\DependencyInjection\Loader;
108- use Symfony\Component\HttpKernel\DependencyInjection\Extension;
109-
110- class AcmeExampleExtension extends Extension
111- {
112- public const ACME_CONFIG_DIR = __DIR__ . '/../../../config/acme';
113-
114- /**
115- * @throws \Exception
116- */
117- public function load(array $configs, ContainerBuilder $container) : void
118- {
119- $configuration = $this->getConfiguration($configs, $container);
120- $config = $this->processConfiguration($configuration, $configs);
121-
122- $loader = new Loader\YamlFileLoader($container, new FileLocator(self::ACME_CONFIG_DIR));
123- $loader->load('default_settings.yaml');
124-
125- $processor = new ConfigurationProcessor($container, 'acme_example');
126- $processor->mapConfig(
127- $config,
128- // Any kind of callable can be used here.
129- // It is called for each declared scope/SiteAccess.
130- static function ($scopeSettings, $currentScope, ContextualizerInterface $contextualizer) {
131- // Maps the "name" setting to "acme_example.<$currentScope>.name" container parameter
132- // It is then possible to retrieve this parameter through ConfigResolver in the application code :
133- // $helloSetting = $configResolver->getParameter( 'name', 'acme_example' );
134- $contextualizer->setContextualParameter('name', $currentScope, $scopeSettings['name']);
135- }
136- );
137-
138- // Now map "custom_setting" and ensure the key defined for "my_siteaccess" overrides the one for "my_siteaccess_group"
139- // It is done outside the closure as it's needed only once.
140- $processor->mapConfigArray('custom_setting', $config);
141- }
142- }
71+ [[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 0, 41) =]]
72+ [[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 53, 61) =]]
14373```
14474
14575You can also map simple settings by calling ` $processor->mapSetting() ` , without having to call ` $processor->mapConfig() ` with a callable.
14676
14777``` php
148- $processor = new ConfigurationProcessor($container, 'acme_example');
149- $processor->mapSetting('name', $config);
78+ [[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 44, 46) =]]
15079```
15180
15281!!! caution "Important"
@@ -171,7 +100,7 @@ but enrich them by appending new entries.
171100This is possible by using ` $processor->mapConfigArray()`, which you must call outside the closure (before or after), so that it's called only once.
172101
173102` ` ` php
174- $processor->mapConfigArray('custom_setting ', $config);
103+ [[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php ', 48, 49) =]]
175104` ` `
176105
177106Consider the following default config in `default_settings.yaml` :
@@ -225,7 +154,7 @@ However, because you defined the `os_types` key for `siteaccess1`, it completely
225154You can add another level by passing `ContextualizerInterface::MERGE_FROM_SECOND_LEVEL` as the third argument to `$contextualizer->mapConfigArray()` :
226155
227156` ` ` php
228- $contextualizer->mapConfigArray('custom_setting ', $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL);
157+ [[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php ', 51, 53) =]]
229158` ` `
230159
231160When you use `ContextualizerInterface::MERGE_FROM_SECOND_LEVEL` with the configuration above, you get the following result :
0 commit comments