diff --git a/src/EventListener/MeilisearchEventContextListener.php b/src/EventListener/MeilisearchEventContextListener.php new file mode 100644 index 0000000..a8c715d --- /dev/null +++ b/src/EventListener/MeilisearchEventContextListener.php @@ -0,0 +1,32 @@ +id; + + // Minimaler, stabiler Marker + $marker = "\n\n"; + + return $buffer . $marker; + } + + return $buffer; + } +} \ No newline at end of file diff --git a/src/EventListener/MeilisearchPageMarkerListener.php b/src/EventListener/MeilisearchPageMarkerListener.php index 3bc43a9..1929a69 100644 --- a/src/EventListener/MeilisearchPageMarkerListener.php +++ b/src/EventListener/MeilisearchPageMarkerListener.php @@ -16,11 +16,9 @@ class MeilisearchPageMarkerListener } $lines = ['MEILISEARCH']; + $page = $GLOBALS['objPage']; - // ========================= - // PAGE - // ========================= - $page = $GLOBALS['objPage']; + /* ================= PAGE ================= */ if ((int) $page->priority > 0) { $lines[] = 'page.priority=' . (int) $page->priority; @@ -30,7 +28,6 @@ class MeilisearchPageMarkerListener $lines[] = 'page.keywords=' . trim((string) $page->keywords); } - // searchimage (Page → Fallback) $searchImageUuid = null; if (!empty($page->searchimage)) { @@ -43,27 +40,25 @@ class MeilisearchPageMarkerListener $lines[] = 'page.searchimage=' . $searchImageUuid; } - // ========================= - // EVENT (Detailseite!) - // ========================= - if ( - isset($GLOBALS['objEvent']) && - $GLOBALS['objEvent'] instanceof CalendarEventsModel - ) { - $event = $GLOBALS['objEvent']; + /* ================= EVENT ================= */ - if ((int) $event->priority > 0) { - $lines[] = 'event.priority=' . (int) $event->priority; - } + if (preg_match('//', $buffer, $m)) { + $eventId = (int) $m[1]; + $event = CalendarEventsModel::findByPk($eventId); - if (trim((string) $event->keywords) !== '') { - $lines[] = 'event.keywords=' . trim((string) $event->keywords); + if ($event !== null) { + if ((int) $event->priority > 0) { + $lines[] = 'event.priority=' . (int) $event->priority; + } + + if (trim((string) $event->keywords) !== '') { + $lines[] = 'event.keywords=' . trim((string) $event->keywords); + } } } - // ========================= - // OUTPUT - // ========================= + /* ================= OUTPUT ================= */ + if (count($lines) === 1) { return $buffer; } diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index 3a550e8..5a8d432 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -2,6 +2,7 @@ use MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener; use MummertMedia\ContaoMeilisearchBundle\EventListener\MeilisearchPageMarkerListener; +use MummertMedia\ContaoMeilisearchBundle\EventListener\MeilisearchEventContextListener; $GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = [ @@ -14,6 +15,10 @@ $GLOBALS['TL_HOOKS']['indexPage'][] = [ 'onIndexPage' ]; +$GLOBALS['TL_HOOKS']['parseFrontendTemplate'][] = [ + MeilisearchEventContextListener::class, + 'onParseFrontendTemplate', +]; if (!isset($GLOBALS['MEILISEARCH_MARKERS'])) { $GLOBALS['MEILISEARCH_MARKERS'] = [];