PrestaSitemapBundle icon indicating copy to clipboard operation
PrestaSitemapBundle copied to clipboard

Routes generated twice in the XML

Open timo002 opened this issue 4 months ago • 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:

  • https://domain.loc/nl/over-ons
  • https://domein.loc/de/ueber-uns

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?

timo002 avatar Feb 12 '24 20:02 timo002