EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Allow defaultLocale to be null

Open gassan opened this issue 3 months ago • 1 comments

Title:
Localized routes work only for DashboardController, not for CrudControllers when using prefix-based locale configuration


Description:

I'm trying to control the current Symfony _locale using the prefix configuration in easyadmin.routes:

easyadmin:
    resource: .
    type: easyadmin.routes
    prefix:
        en: '/en'
        de: ''

However, with this setup, localized links are generated only for the DashboardControllers, while CrudControllers do not get the proper locale prefixes.

When I change the defaultLocale parameter to null via a CompilerPass, all routes are generated correctly and everything works as expected.

CompierPass

use EasyCorp\Bundle\EasyAdminBundle\Router\AdminRouteGenerator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AllowLocaleInPrefixRoutesForEasyAdminPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $container->findDefinition(AdminRouteGenerator::class)
            ->setArgument(5, null)
        ;
    }
}

Note:
There is probably a more correct way to handle this, but this workaround works for now.

gassan avatar Oct 27 '25 15:10 gassan

Related to https://github.com/EasyCorp/EasyAdminBundle/pull/6954

andersonamuller avatar Oct 27 '25 23:10 andersonamuller