Skip to content

Conversation

mnocon
Copy link
Contributor

@mnocon mnocon commented Jul 14, 2025

Follow-up to ibexa/fieldtype-matrix#66

I've extracted the code samples to a separate files.

I've done the following changes in them:

        $contextualizer = $processor->getContextualizer();
        $contextualizer->mapConfigArray('custom_setting', $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL);

I think it's better showcases where to get the $contextualizer from.

@github-actions
Copy link

Preview of modified files

Preview of modified Markdown:

@mnocon mnocon marked this pull request as ready for review July 15, 2025 09:44
@mnocon mnocon requested a review from a team July 15, 2025 09:47
@ezrobot ezrobot requested review from adriendupuis, dabrt and julitafalcondusza and removed request for a team July 15, 2025 09:47
@mnocon mnocon changed the title V5 adjustments siteaccess [V5] Adjusted SiteAccess configuration example Jul 15, 2025
@github-actions
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/multisite/siteaccess/AcmeExampleExtension.php


code_samples/multisite/siteaccess/AcmeExampleExtension.php

docs/multisite/siteaccess/siteaccess_aware_configuration.md@70:``` php
docs/multisite/siteaccess/siteaccess_aware_configuration.md@71:[[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 0, 42) =]][[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 53, 61) =]]
docs/multisite/siteaccess/siteaccess_aware_configuration.md@72:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace Acme\ExampleBundle\DependencyInjection;
004⫶
005⫶use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
006⫶use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
007⫶use Symfony\Component\Config\FileLocator;
008⫶use Symfony\Component\DependencyInjection\ContainerBuilder;
009⫶use Symfony\Component\DependencyInjection\Extension\Extension;
010⫶use Symfony\Component\DependencyInjection\Loader;
011⫶
012⫶final class AcmeExampleExtension extends Extension
013⫶{
014⫶ public const ACME_CONFIG_DIR = __DIR__ . '/../../../config/acme';
015⫶
016⫶ /**
017⫶ * @throws \Exception
018⫶ */
019⫶ public function load(array $configs, ContainerBuilder $container): void
020⫶ {
021⫶ $configuration = $this->getConfiguration($configs, $container);
022⫶ $config = $this->processConfiguration($configuration, $configs);
023⫶
024⫶ $loader = new Loader\YamlFileLoader($container, new FileLocator(self::ACME_CONFIG_DIR));
025⫶ $loader->load('default_settings.yaml');
026⫶
027⫶ $processor = new ConfigurationProcessor($container, 'acme_example');
028⫶ $processor->mapConfig(
029⫶ $config,
030⫶ // Any kind of callable can be used here.
031⫶ // It is called for each declared scope/SiteAccess.
032⫶ static function ($scopeSettings, $currentScope, ContextualizerInterface $contextualizer) {
033⫶ // Maps the "name" setting to "acme_example.<$currentScope>.name" container parameter
034⫶ // It is then possible to retrieve this parameter through ConfigResolver in the application code:
035⫶ // $helloSetting = $configResolver->getParameter( 'name', 'acme_example' );
036⫶ $contextualizer->setContextualParameter('name', $currentScope, $scopeSettings['name']);
037⫶ }
038⫶ );
039⫶
040⫶ // Now map "custom_setting" and ensure the key defined for "my_siteaccess" overrides the one for "my_siteaccess_group"
041⫶ // It is done outside the closure as it's needed only once.
042⫶ $processor->mapConfigArray('custom_setting', $config);
043⫶ }
044⫶
045⫶ /** @param array<mixed> $config */
046⫶ public function getConfiguration(array $config, ContainerBuilder $container): Configuration
047⫶ {
048⫶ return new Configuration();
049⫶ }
050⫶}

docs/multisite/siteaccess/siteaccess_aware_configuration.md@76:``` php
docs/multisite/siteaccess/siteaccess_aware_configuration.md@77:[[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 44, 46) =]]
docs/multisite/siteaccess/siteaccess_aware_configuration.md@78:```

001⫶ $processor = new ConfigurationProcessor($container, 'acme_example');
002⫶ $processor->mapSetting('name', $config);

docs/multisite/siteaccess/siteaccess_aware_configuration.md@101:``` php
docs/multisite/siteaccess/siteaccess_aware_configuration.md@102:[[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 48, 49) =]]
docs/multisite/siteaccess/siteaccess_aware_configuration.md@103:```

001⫶ $processor->mapConfigArray('custom_setting', $config);

docs/multisite/siteaccess/siteaccess_aware_configuration.md@155:``` php
docs/multisite/siteaccess/siteaccess_aware_configuration.md@156:[[= include_file('code_samples/multisite/siteaccess/AcmeExampleExtension.php', 51, 53) =]]
docs/multisite/siteaccess/siteaccess_aware_configuration.md@157:```

001⫶ $contextualizer = $processor->getContextualizer();
002⫶ $contextualizer->mapConfigArray('custom_setting', $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL);


code_samples/multisite/siteaccess/Configuration.php


code_samples/multisite/siteaccess/Configuration.php

docs/multisite/siteaccess/siteaccess_aware_configuration.md@38:``` php hl_lines="16"
docs/multisite/siteaccess/siteaccess_aware_configuration.md@39:[[= include_file('code_samples/multisite/siteaccess/Configuration.php') =]]
docs/multisite/siteaccess/siteaccess_aware_configuration.md@40:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace Acme\ExampleBundle\DependencyInjection;
004⫶
005⫶use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
006⫶use Symfony\Component\Config\Definition\Builder\TreeBuilder;
007⫶
008⫶class Configuration extends SiteAccessConfiguration
009⫶{
010⫶ public function getConfigTreeBuilder(): TreeBuilder
011⫶ {
012⫶ $treeBuilder = new TreeBuilder('acme_example');
013⫶ $rootNode = $treeBuilder->getRootNode();
014⫶
015⫶ // $systemNode is the root of SiteAccess-aware settings.
016❇️ $systemNode = $this->generateScopeBaseNode($rootNode);
017⫶ $systemNode
018⫶ ->scalarNode('name')->isRequired()->end()
019⫶ ->arrayNode('custom_setting')
020⫶ ->children()
021⫶ ->scalarNode('string')->end()
022⫶ ->integerNode('number')->end()
023⫶ ->booleanNode('enabled')->end()
024⫶ ->end()
025⫶ ->end();
026⫶
027⫶ return $treeBuilder;
028⫶ }
029⫶}

Download colorized diff

@mnocon mnocon merged commit 3ab5083 into 5.0 Jul 15, 2025
6 of 7 checks passed
@mnocon mnocon deleted the v5-adjustments-siteaccess branch July 15, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants