Symfony Bundle – values not updating when changing /packages/.yaml

I’m working on a Symfony bundle at the moment and have got it working apart from one issue which I am really struggling to figure out.

In my bundles Extension file I ensure entity_tables.yaml is created in the installing projects config/packages/ directory:

// entity-tables-bundle/src/DependencyInjection/EntityTablesExtension.php
public function load(array $configs, ContainerBuilder $container): void
{
    $configuration = new Configuration();
    $config = $this->processConfiguration($configuration, $configs);

    $yamlConfig = [
        'entity_tables' => $config,
    ];
    $yaml = Yaml::dump($yamlConfig, 4);

    $yamlFilePath = $container->getParameter('kernel.project_dir') . '/config/packages/entity_tables.yaml';

    file_put_contents($yamlFilePath, $yaml);

    $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
    $loader->load('entity_tables.yaml');

    $this->modifyTwigConfiguration($container);
}

private function modifyTwigConfiguration(ContainerBuilder $container): void
{
    $twigConfigFile = $container->getParameter('kernel.project_dir') . '/config/packages/twig.yaml';
    $twigConfig = Yaml::parseFile($twigConfigFile);

    if (!isset($twigConfig['twig']['paths']['%kernel.project_dir%/vendor/dannyxcii/entity-tables-bundle/src/Resources/views'])) {
        $twigConfig['twig']['paths']['%kernel.project_dir%/vendor/dannyxcii/entity-tables-bundle/src/Resources/views'] = 'EntityTables';
    }

    if (!isset($twigConfig['twig']['globals']['entity_tables_currency'])) {
        $twigConfig['twig']['globals']['entity_tables_currency'] = '%entity_tables.currency%';
    }

    $dumper = new Dumper();
    $yaml = $dumper->dump($twigConfig, 4);

    file_put_contents($twigConfigFile, $yaml);
}

The modifyTwigConfiguration method adds a global and the namespace for the twig templates which wasn’t getting done automatically as the Symfony docs state. My Configuration is very simple:

// entity-tables-bundle/src/DependencyInjection/Configuration.php
public function getConfigTreeBuilder(): TreeBuilder
{
    $treeBuilder = new TreeBuilder('entity_tables');

    $treeBuilder->getRootNode()
        ->children()
            ->scalarNode('currency')
            ->defaultValue('£')
            ->end()
        ->end();

    return $treeBuilder;
}

And the contents of my packages entity_tables.yaml:

parameters:
  entity_tables.currency: '£'

Which adds this config to my app:

entity_tables:
  currency: £

So now when my bundle is installed via Composer, the bundle is added automatically to config/bundles.php and my YAML file is created as shown above. I can access this in my controllers with $this->getParameter('entity_tables.currency') and in my templates with entity_tables_currency.

Question: When I update the value in config/packages/entity_tables.yaml (to $), the value is not updated when accessing – £ is still displayed. Does anyone know why?

What I tried: I have tried:

  • bin/console cache:clear --env=prod + bin/console cache:clear --env=dev
  • Ran php bin/console debug:container --parameters and the param still displays the original/default value
  • Restarted Docker containers and cleared browser cache

I am using Symfony 6.2.