prestaconcept / PrestaSitemapBundle

A symfony bundle that provides tools to build a rich application sitemap. The main goals are : simple, no databases, various namespace (eg. google image), respect constraints etc.
MIT License
347 stars 100 forks source link

Routes generated twice in the XML #338

Open timo002 opened 4 months ago

timo002 commented 4 months ago

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?

yann-eugone commented 4 months ago

If you remove that listener, you have 0 route registered ?

timo002 commented 4 months ago

Yes, it is a dynamic URL so if I remove the listener noting is running the code for generating the XML

yann-eugone commented 4 months ago

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());
}