Passed
Push — master ( f63a3e...201a83 )
by Timo
34:43
created

FormCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1.0046
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Plugin\Results;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2009-2015 Ingo Renner <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\Plugin\CommandPluginAware;
28
use ApacheSolrForTypo3\Solr\Plugin\CommandPluginBase;
29
use ApacheSolrForTypo3\Solr\Plugin\FormModifier;
30
use ApacheSolrForTypo3\Solr\Plugin\PluginCommand;
31
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
34
35
/**
36
 * form command class to render the "simple" search form
37
 *
38
 * @author Ingo Renner <[email protected]>
39
 */
40
class FormCommand implements PluginCommand
41
{
42
43
    /**
44
     *
45
     * @var ContentObjectRenderer
46
     */
47
    protected $cObj;
48
49
    /**
50
     * Parent plugin
51
     *
52
     * @var CommandPluginBase
53
     */
54
    protected $parentPlugin;
55
56
    /**
57
     * Configuration
58
     *
59
     * @var TypoScriptConfiguration
60
     */
61
    protected $configuration;
62
63
    /**
64
     * Constructor for class ApacheSolrForTypo3\Solr\Plugin\Results\FormCommand
65
     *
66
     * @param CommandPluginBase $parentPlugin parent plugin
67
     */
68 25
    public function __construct(CommandPluginBase $parentPlugin)
69
    {
70 25
        $this->cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
71
72 25
        $this->parentPlugin = $parentPlugin;
73 25
        $this->configuration = $parentPlugin->typoScriptConfiguration;
74 25
    }
75
76
    /**
77
     * Provides the values for the markers in the simple form template
78
     *
79
     * @return array An array containing values for markers in the simple form template
80
     * @throws \InvalidArgumentException if an registered form modifier fails to implement the required interface ApacheSolrForTypo3\Solr\Plugin\FormModifier
81
     */
82 25
    public function execute()
83
    {
84 25
        $url = $this->cObj->getTypoLink_URL($this->parentPlugin->typoScriptConfiguration->getSearchTargetPage());
85
86
        $marker = [
87 25
            'action' => htmlspecialchars($url),
88 25
            'action_id' => intval($this->parentPlugin->typoScriptConfiguration->getSearchTargetPage()),
89 25
            'action_language' => intval($GLOBALS['TSFE']->sys_page->sys_language_uid),
90 25
            'action_language_parameter' => 'L',
91 25
            'accept-charset' => $GLOBALS['TSFE']->metaCharset,
92 25
            'q' => $this->parentPlugin->getCleanUserQuery()
93
        ];
94
95
        // hook to modify the search form
96 25
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchForm'])) {
97 25
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchForm'] as $classReference) {
98 25
                $formModifier = GeneralUtility::getUserObj($classReference);
99
100 25
                if ($formModifier instanceof FormModifier) {
101 25
                    if ($formModifier instanceof CommandPluginAware) {
102 25
                        $formModifier->setParentPlugin($this->parentPlugin);
103
                    }
104
105 25
                    $marker = $formModifier->modifyForm($marker,
106 25
                        $this->parentPlugin->getTemplate());
107
                } else {
108
                    throw new \InvalidArgumentException(
109
                        'Form modifier "' . $classReference . '" must implement the ApacheSolrForTypo3\Solr\Plugin\FormModifier interface.',
110 25
                        1262864703
111
                    );
112
                }
113
            }
114
        }
115
116 25
        return $marker;
117
    }
118
}
119