Skip to content

[Bundles] [Bundle] Fix code example about prepend config #16808

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

Merged
merged 1 commit into from
May 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions bundles/prepend_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,18 @@ in case a specific other bundle is not registered::
}
}

// process the configuration of AcmeHelloExtension
// get the configuration of AcmeHelloExtension (it's a list of configuration)
$configs = $container->getExtensionConfig($this->getAlias());

// resolve config parameters e.g. %kernel.debug% to its boolean value
$resolvingBag = $container->getParameterBag();
$configs = $resolvingBag->resolveValue($configs);

// use the Configuration class to generate a config array with
// the settings "acme_hello"
$config = $this->processConfiguration(new Configuration(), $configs);

// check if entity_manager_name is set in the "acme_hello" configuration
if (isset($config['entity_manager_name'])) {
// prepend the acme_something settings with the entity_manager_name
$config = ['entity_manager_name' => $config['entity_manager_name']];
$container->prependExtensionConfig('acme_something', $config);
// iterate in reverse to preserve the original order after prepending the config
foreach (array_reverse($configs) as $config) {
// check if entity_manager_name is set in the "acme_hello" configuration
if (isset($config['entity_manager_name'])) {
// prepend the acme_something settings with the entity_manager_name
$container->prependExtensionConfig('acme_something', [
'entity_manager_name' => $config['entity_manager_name'],
]);
}
}
}

Expand Down