Passed
Push — master ( 0ba0e3...644d9b )
by Timo
19:06
created

AddSearchWordListViewHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 8 1
A renderStatic() 0 19 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Uri\Result;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\Domain\Search\Highlight\SiteHighlighterUrlModifier;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
19
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23
24
/**
25
 * Class AddSearchWordListViewHelper
26
 *
27
 * @author Timo Hund <[email protected]>
28
 * @package ApacheSolrForTypo3\Solr\ViewHelpers\Document
29
 */
30
class AddSearchWordListViewHelper extends AbstractSolrFrontendViewHelper
31
{
32
    use CompileWithRenderStatic;
33
34
    /**
35
     * @var bool
36
     */
37
    protected $escapeOutput = false;
38
39
    /**
40
     * Initializes the arguments
41
     */
42
    public function initializeArguments()
43
    {
44
        parent::initializeArguments();
45
        $this->registerArgument('url', 'string', 'The context searchResultSet', true);
46
        $this->registerArgument('searchWords', 'string', 'The document to highlight', true);
47
        $this->registerArgument('addNoCache', 'boolean', 'Should no_cache=1 be added or not', false, true);
48
        $this->registerArgument('keepCHash', 'boolean', 'Should cHash be kept or not', false, false);
49
    }
50
51
    /**
52
     * @param array $arguments
53
     * @param \Closure $renderChildrenClosure
54
     * @param RenderingContextInterface $renderingContext
55
     * @return string
56
     */
57
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
58
    {
59
        $url = $arguments['url'];
60
61
            /** @var $resultSet SearchResultSet */
62
        $resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
63
        if (!$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchResultsSiteHighlighting()) {
64
            return $url;
65
        }
66
67
        $searchWords = $arguments['searchWords'];
68
        $addNoCache = $arguments['addNoCache'];
69
        $keepCHash = $arguments['keepCHash'];
70
71
        /** @var $siteHighlighterUrlModifier SiteHighlighterUrlModifier */
72
        $siteHighlighterUrlModifier = GeneralUtility::makeInstance(SiteHighlighterUrlModifier::class);
73
74
        return $siteHighlighterUrlModifier->modify($url, $searchWords, $addNoCache, $keepCHash);
75
    }
76
}