Add Index Listener
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
||||
|
||||
use Contao\CalendarEventsModel;
|
||||
use Contao\Template;
|
||||
|
||||
class MeilisearchEventContextListener
|
||||
{
|
||||
public function onParseFrontendTemplate(string $buffer, string $template): string
|
||||
{
|
||||
// Nur Event-Reader-Modul
|
||||
if ($template !== 'mod_eventreader') {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
// Event kommt IM Template an
|
||||
if (
|
||||
isset($GLOBALS['objEvent']) &&
|
||||
$GLOBALS['objEvent'] instanceof CalendarEventsModel
|
||||
) {
|
||||
$eventId = (int) $GLOBALS['objEvent']->id;
|
||||
|
||||
// Minimaler, stabiler Marker
|
||||
$marker = "\n<!-- MEILI_EVENT id={$eventId} -->\n";
|
||||
|
||||
return $buffer . $marker;
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,10 @@ class MeilisearchPageMarkerListener
|
||||
}
|
||||
|
||||
$lines = ['MEILISEARCH'];
|
||||
|
||||
// =========================
|
||||
// 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,15 +40,13 @@ class MeilisearchPageMarkerListener
|
||||
$lines[] = 'page.searchimage=' . $searchImageUuid;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// EVENT (Detailseite!)
|
||||
// =========================
|
||||
if (
|
||||
isset($GLOBALS['objEvent']) &&
|
||||
$GLOBALS['objEvent'] instanceof CalendarEventsModel
|
||||
) {
|
||||
$event = $GLOBALS['objEvent'];
|
||||
/* ================= EVENT ================= */
|
||||
|
||||
if (preg_match('/<!--\s*MEILI_EVENT id=(\d+)\s*-->/', $buffer, $m)) {
|
||||
$eventId = (int) $m[1];
|
||||
$event = CalendarEventsModel::findByPk($eventId);
|
||||
|
||||
if ($event !== null) {
|
||||
if ((int) $event->priority > 0) {
|
||||
$lines[] = 'event.priority=' . (int) $event->priority;
|
||||
}
|
||||
@@ -60,10 +55,10 @@ class MeilisearchPageMarkerListener
|
||||
$lines[] = 'event.keywords=' . trim((string) $event->keywords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================= OUTPUT ================= */
|
||||
|
||||
// =========================
|
||||
// OUTPUT
|
||||
// =========================
|
||||
if (count($lines) === 1) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
@@ -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'] = [];
|
||||
|
||||
Reference in New Issue
Block a user