Skip to content

Commit

Permalink
fix: handle URL generation based on Contao version
Browse files Browse the repository at this point in the history
Add logic to accommodate different URL generation methods for Contao versions below and above 5.0. This ensures compatibility and correct URL formatting for events based on the version in use.
  • Loading branch information
cgoIT committed Oct 18, 2024
1 parent d098472 commit 7cc75bb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Hook/ParseFrontendTemplateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,21 @@ private function processEventTemplate(CalendarEventsModel $objEvent, FrontendTem
$template->getSchemaOrgData = static function () use ($template, $objEvent, $intStartTime, $intEndTime): array {
$jsonLd = Events::getSchemaOrgData($objEvent);

$urlGenerator = System::getContainer()->get('contao.routing.content_url_generator');

try {
$jsonLd['url'] = $urlGenerator->generate($objEvent, ['day' => date('Ymd', $intStartTime), 'times' => $intStartTime.','.$intEndTime]);
} catch (ExceptionInterface) {
// noop
$version = (method_exists(ContaoCoreBundle::class, 'getVersion') ? ContaoCoreBundle::getVersion() : VERSION); // @phpstan-ignore-line

if (version_compare($version, '5.0', '<')) {
$urlParameter = sprintf("day=%s&times=%s", date('Ymd', $intStartTime), $intStartTime.','.$intEndTime);
$jsonLd['url'] .= (str_contains($jsonLd['url'], '?') ? '&' : '?').$urlParameter;
} else {
$urlGenerator = System::getContainer()->get('contao.routing.content_url_generator');

try {
$jsonLd['url'] = $urlGenerator->generate($objEvent, ['day' => date('Ymd', $intStartTime), 'times' => $intStartTime.','.$intEndTime]);
} catch (ExceptionInterface) {
// noop
}
}

$jsonLd['startDate'] = $objEvent->addTime ? date('Y-m-d\TH:i:sP', $template->begin) : date('Y-m-d', $template->begin);

if ($template->addImage && $template->figure) {
Expand Down

0 comments on commit 7cc75bb

Please sign in to comment.