Configuration TreeBuilder merge array instead of replace

I have a bundle that defines some templates in the configuration like this:

my_bundle:
    templates:
        layout: "layout.html.twig"
        sidebar: "sidebar.html.twig"

Now I want to be able to override only 1 of these templates in the app/config.yml like this:

my_bundle:
    templates:
        layout: "custom_layout.html.twig"

and the resulting config should then be:

my_bundle:
    templates:
        layout: "custom.html.twig"
        sidebar: "sidebar.html.twig"

But with the following Configuration class, it will just replace the while templates key with only the values defined in the app/config.yml

$node
    ->children()
        ->arrayNode('templates')               
            ->addDefaultsIfNotSet() // This is not adding the defaults???
            ->children()
                ->scalarNode('layout')->defaultValue('layout.html.twig')->isRequired()->end()
                ->scalarNode('sidebar')->defaultValue('sidebar.html.twig')->isRequired()->end()
            ->end()
        ->end()
    ->end();

Source: New Questions

Leave a Reply