Allow defaultLocale to be null
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.
Related to https://github.com/EasyCorp/EasyAdminBundle/pull/6954