Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes generated twice in the XML #338

Open
timo002 opened this issue Feb 12, 2024 · 3 comments
Open

Routes generated twice in the XML #338

timo002 opened this issue Feb 12, 2024 · 3 comments
Labels

Comments

@timo002
Copy link

timo002 commented Feb 12, 2024

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
Copy link
Member

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

@timo002
Copy link
Author

timo002 commented Feb 13, 2024

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

@yann-eugone
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants