Fix backend survey frontend URL generation

This commit is contained in:
Jürgen Mummert
2026-05-24 16:25:39 +02:00
parent 633fbd2ad9
commit ad9ab32a59
+11 -8
View File
@@ -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