meilisearch/Classes/ViewHelpers/Uri/Result/AddSearchWordListViewHelper.php

71 lines
2.7 KiB
PHP
Raw Normal View History

2021-04-17 00:26:33 +02:00
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Result;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use WapplerSystems\Meilisearch\Domain\Search\Highlight\SiteHighlighterUrlModifier;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
2021-04-17 21:20:54 +02:00
use WapplerSystems\Meilisearch\ViewHelpers\AbstractMeilisearchFrontendViewHelper;
2021-04-17 00:26:33 +02:00
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class AddSearchWordListViewHelper
*
* @author Timo Hund <timo.hund@dkd.de>
*/
2021-04-17 21:20:54 +02:00
class AddSearchWordListViewHelper extends AbstractMeilisearchFrontendViewHelper
2021-04-17 00:26:33 +02:00
{
use CompileWithRenderStatic;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('url', 'string', 'The context searchResultSet', true);
$this->registerArgument('searchWords', 'string', 'The document to highlight', true);
$this->registerArgument('addNoCache', 'boolean', 'Should no_cache=1 be added or not', false, true);
$this->registerArgument('keepCHash', 'boolean', 'Should cHash be kept or not', false, false);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$url = $arguments['url'];
/** @var $resultSet SearchResultSet */
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
if (!$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchResultsSiteHighlighting()) {
return $url;
}
$searchWords = $arguments['searchWords'];
$addNoCache = $arguments['addNoCache'];
$keepCHash = $arguments['keepCHash'];
/** @var $siteHighlighterUrlModifier SiteHighlighterUrlModifier */
$siteHighlighterUrlModifier = GeneralUtility::makeInstance(SiteHighlighterUrlModifier::class);
return $siteHighlighterUrlModifier->modify($url, $searchWords, $addNoCache, $keepCHash);
}
}