0
votes

I'm making a bundle in Symfony 4, but in my bundle I use FOSUserBundle. So I would like to defined configuration for FOSUserBundle from my own bundle and not from the main configuration. How to do it ? It doesn't recognize the node

There is no extension able to load the configuration for "fos_user" (in C:\wamp64\www\MyProject\src\CMSBundle\DependencyInjection/../Resources/config\fos_user.yaml). Looked for namespace "fos_user", found none

And if I load the configuration of FOSUserBundle (FOS\UserBundle\DependencyInjection/Configuration.php) in my CMSExtension.php

I'm getting this message

The child node "db_driver" at path "fos_user" must be configured.

Structure

/src
    /CMSBundle
        /Controller
        /DependencyInjection
            CMSExtension.php
        /Entity
        /Repository
        /Resources
            /config
                fos_user.yaml
                routing.yaml
                security.yaml
                services.yaml
        CMSBundle.php

src/CMSBundle/DependencyInjection/CMSExtension.php

class CMSExtension extends Extension {

    public function load(array $configs, ContainerBuilder $container) {
        $loader = new YamlFileLoader(
            $container,
            new FileLocator(__DIR__ . '/../Resources/config')
        );
        $loader->load('services.yaml');
        $loader->load('security.yaml');
        $loader->load('fos_user.yaml');
    }

}

src/CMSBundle/Resourcers/config/fos_user.yaml

fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: src\CMSBundle\Entity\User
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"
1

1 Answers

3
votes

In your CMSExtension class, you can implement the PrependExtensionInterface and add a prepend method.

In this method, you'll be able to override the FOSUserBundle configuration:

/**
 * {@inheritdoc}
 */
public function prepend(ContainerBuilder $container)
{
    $newConfig = [
        'db_driver' => '',
        ...
    ];

    $container->prependExtensionConfig('fos_user', $newConfig);
}

Look a this page in the Symfony documentation.