Routes generated twice in the XML
timo002 opened this issue · 3 comments
I created a EventListener for dynamic routes and my app is multilanguage (nl / de). I created landingpages that are multilanguage, for example the following two URL's exist:
I'm using the following route:
#[Route('/{_locale}/{permalink}', name: 'webshop_landingpage', requirements: ['_locale' => '%app.locales%'], methods: ['GET'], priority: -1)]
The following code is used in
public function registerLandingPageUrls(UrlContainerInterface $urls, UrlGeneratorInterface $router): void
{
$pages = $this->landingPageRepository->findAll();
foreach ($pages as $page) {
foreach ($page->getTranslations() as $translation) {
$urls->addUrl(
new UrlConcrete(
$router->generate(
'webshop_landingpage',
[
'_locale' => strtolower($translation->getLanguage()->getIso()),
'permalink' => $translation->getPermalink(),
],
UrlGeneratorInterface::ABSOLUTE_URL
)
),
'landingpage'
);
}
}
}
But now it adds each URL twice in the XML file, first a set of the NL and DE version. And then the same URLs again.
<url>
<loc>https://domain.loc/nl/over-ons</loc>
<lastmod>2024-02-12T21:35:07+01:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://domain.loc/de/ueber-uns</loc>
<lastmod>2024-02-12T21:35:07+01:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
// other URLs
<url>
<loc>https://domain.loc/nl/over-ons</loc>
<lastmod>2024-02-12T21:35:07+01:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://domain.loc/de/ueber-uns</loc>
<lastmod>2024-02-12T21:35:07+01:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
Any idea how I can fix this?
If you remove that listener, you have 0 route registered ?
Yes, it is a dynamic URL so if I remove the listener noting is running the code for generating the XML
So, it means that your listener is called twice
Can you show the calls traces ?
XDebug or
try {
throw new \Exception();
} catch (\Throwable $exception) {
dump($exception->getTraceAsString());
}