From ad9ab32a59fd18389d5db16a3f0f586eba15ee16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Mummert?= Date: Sun, 24 May 2026 16:25:39 +0200 Subject: [PATCH] Fix backend survey frontend URL generation --- src/EventListener/SurveyDcaListener.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/EventListener/SurveyDcaListener.php b/src/EventListener/SurveyDcaListener.php index 22c37ac..7aafa9e 100644 --- a/src/EventListener/SurveyDcaListener.php +++ b/src/EventListener/SurveyDcaListener.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Mummert\SurveyBundle\EventListener; use Contao\Config; +use Contao\CoreBundle\Routing\ContentUrlGenerator; use Contao\CoreBundle\Framework\ContaoFramework; use Contao\DataContainer; -use Contao\Environment; use Contao\Image; use Contao\Input; use Contao\PageModel; @@ -16,6 +16,7 @@ use Mummert\SurveyBundle\Repository\SurveyEditorRepository; use Mummert\SurveyBundle\Repository\SurveyQuestionRepository; use Mummert\SurveyBundle\Repository\SurveyRepository; use Mummert\SurveyBundle\Service\SurveyCategoryAssignmentService; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; final class SurveyDcaListener { @@ -26,6 +27,7 @@ final class SurveyDcaListener private readonly SurveyCategoryAssignmentService $surveyCategoryAssignmentService, private readonly ContaoFramework $framework, private readonly Connection $connection, + private readonly ContentUrlGenerator $contentUrlGenerator, ) { } @@ -462,14 +464,15 @@ final class SurveyDcaListener return null; } - $baseUrl = rtrim((string) $this->framework->getAdapter(Environment::class)->get('url'), '/'); - $pagePath = trim((string) $page->getFrontendUrl(), '/'); - - if ('' === $pagePath) { - return sprintf('%s/%s', $baseUrl, $alias); + try { + return $this->contentUrlGenerator->generate( + $page, + ['parameters' => '/'.$alias], + UrlGeneratorInterface::ABSOLUTE_URL, + ); + } catch (\Throwable) { + return null; } - - return sprintf('%s/%s/%s', $baseUrl, $pagePath, $alias); } private function resolvePageId(string $settingKey): int