Skip to content

Commit

Permalink
fix: set correct start date and url in schema.org data
Browse files Browse the repository at this point in the history
  • Loading branch information
cgoIT committed Sep 4, 2024
1 parent 19bf28d commit 1a7b3aa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Hook/ParseFrontendTemplateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Contao\PageModel;
use Contao\StringUtil;
use Contao\System;
use Symfony\Component\Routing\Exception\ExceptionInterface;

#[AsHook(hook: 'parseFrontendTemplate')]
class ParseFrontendTemplateHook extends Controller
Expand Down Expand Up @@ -253,9 +254,18 @@ private function processEventTemplate(CalendarEventsModel $objEvent, FrontendTem
}

// schema.org information
$template->getSchemaOrgData = static function () use ($template, $objEvent): array {
$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
}
$jsonLd['startDate'] = $objEvent->addTime ? date('Y-m-d\TH:i:sP', $template->begin) : date('Y-m-d', $template->begin);

if ($template->addImage && $template->figure) {
$jsonLd['image'] = $template->figure->getSchemaOrgData();
}
Expand Down

0 comments on commit 1a7b3aa

Please sign in to comment.