Hello everyone,
I am trying to customize the output of The TNT search plugin. I am following the explanations available on the plugin page:
I have added the following functions in the php file of my theme:
<?php
namespace Grav\Theme;
use Grav\Common\Theme;
class NixholTemplate extends Theme
{
public static function getSubscribedEvents() {
return [
'onTNTSearchQuery' => ['onTNTSearchQuery', 1000],
];
}
public function onTNTSearchQuery(Event $e) {
$query = $this->grav['uri']->param('q');
if ($query) {
$page = $e['page'];
$query = $e['query'];
$options = $e['options'];
$fields = $e['fields'];
$gtnt = $e['gtnt'];
$content = $gtnt->getCleanContent($page);
$title = $page->title();
$relevant = $gtnt->tnt->snippet($query, $content, $options['snippet']);
if (strlen($relevant) <= 6) {
$relevant = substr($content, 0, $options['snippet']);
}
$fields->hits[] = [
'link' => $page->route(),
'title' => $gtnt->tnt->highlight($title, $query, 'em', ['wholeWord' => false]),
'content' => $gtnt->tnt->highlight($relevant, $query, 'em', ['wholeWord' => false]),
];
$e->stopPropagation();
}
}
}
?>
But when I test the plugin I am running into this error:
Argument 1 passed to Grav\Theme\NixholTemplate::onTNTSearchQuery() must be an instance of Grav\Theme\Event
Do you know what I am doing wrong? Thanks in advance for your help!
Nicolas