Fix backend survey frontend URL generation
This commit is contained in:
@@ -5,9 +5,9 @@ declare(strict_types=1);
|
|||||||
namespace Mummert\SurveyBundle\EventListener;
|
namespace Mummert\SurveyBundle\EventListener;
|
||||||
|
|
||||||
use Contao\Config;
|
use Contao\Config;
|
||||||
|
use Contao\CoreBundle\Routing\ContentUrlGenerator;
|
||||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||||
use Contao\DataContainer;
|
use Contao\DataContainer;
|
||||||
use Contao\Environment;
|
|
||||||
use Contao\Image;
|
use Contao\Image;
|
||||||
use Contao\Input;
|
use Contao\Input;
|
||||||
use Contao\PageModel;
|
use Contao\PageModel;
|
||||||
@@ -16,6 +16,7 @@ use Mummert\SurveyBundle\Repository\SurveyEditorRepository;
|
|||||||
use Mummert\SurveyBundle\Repository\SurveyQuestionRepository;
|
use Mummert\SurveyBundle\Repository\SurveyQuestionRepository;
|
||||||
use Mummert\SurveyBundle\Repository\SurveyRepository;
|
use Mummert\SurveyBundle\Repository\SurveyRepository;
|
||||||
use Mummert\SurveyBundle\Service\SurveyCategoryAssignmentService;
|
use Mummert\SurveyBundle\Service\SurveyCategoryAssignmentService;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
final class SurveyDcaListener
|
final class SurveyDcaListener
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,7 @@ final class SurveyDcaListener
|
|||||||
private readonly SurveyCategoryAssignmentService $surveyCategoryAssignmentService,
|
private readonly SurveyCategoryAssignmentService $surveyCategoryAssignmentService,
|
||||||
private readonly ContaoFramework $framework,
|
private readonly ContaoFramework $framework,
|
||||||
private readonly Connection $connection,
|
private readonly Connection $connection,
|
||||||
|
private readonly ContentUrlGenerator $contentUrlGenerator,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,14 +464,15 @@ final class SurveyDcaListener
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseUrl = rtrim((string) $this->framework->getAdapter(Environment::class)->get('url'), '/');
|
try {
|
||||||
$pagePath = trim((string) $page->getFrontendUrl(), '/');
|
return $this->contentUrlGenerator->generate(
|
||||||
|
$page,
|
||||||
if ('' === $pagePath) {
|
['parameters' => '/'.$alias],
|
||||||
return sprintf('%s/%s', $baseUrl, $alias);
|
UrlGeneratorInterface::ABSOLUTE_URL,
|
||||||
|
);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf('%s/%s/%s', $baseUrl, $pagePath, $alias);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolvePageId(string $settingKey): int
|
private function resolvePageId(string $settingKey): int
|
||||||
|
|||||||
Reference in New Issue
Block a user