28
28
*
29
29
* This copyright notice MUST APPEAR in all copies of the script!
30
30
* ************************************************************* */
31
-
31
+ use Psr \Http \Message \ResponseInterface ;
32
+ use Psr \Log \LoggerInterface ;
32
33
use Subugoe \Find \Service \ServiceProviderInterface ;
33
34
use Subugoe \Find \Utility \ArrayUtility ;
34
35
use Subugoe \Find \Utility \FrontendUtility ;
35
36
use TYPO3 \CMS \Core \Log \LogManagerInterface ;
37
+ use TYPO3 \CMS \Core \Page \AssetCollector ;
36
38
use TYPO3 \CMS \Core \Utility \ArrayUtility as CoreArrayUtility ;
37
39
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
40
+ use TYPO3 \CMS \Extbase \Http \ForwardResponse ;
38
41
use TYPO3 \CMS \Extbase \Mvc \Controller \ActionController ;
42
+ use TYPO3 \CMS \Extbase \Mvc \Exception \NoSuchArgumentException ;
43
+ use TYPO3 \CMS \Extbase \Mvc \Exception \StopActionException ;
39
44
40
45
class SearchController extends ActionController
41
46
{
42
47
protected array $ requestArguments = [];
43
48
44
49
protected ?object $ searchProvider = null ;
45
50
46
- private \ Psr \ Log \ LoggerInterface $ logger ;
51
+ private LoggerInterface $ logger ;
47
52
48
53
public function __construct (LogManagerInterface $ logManager )
49
54
{
50
55
$ this ->logger = $ logManager ->getLogger ('find ' );
51
56
}
52
57
53
58
/**
54
- * @throws \TYPO3\CMS\Extbase\Mvc\Exception\ NoSuchArgumentException
55
- * @throws \TYPO3\CMS\Extbase\Mvc\Exception\ StopActionException
59
+ * @throws NoSuchArgumentException
60
+ * @throws StopActionException
56
61
*/
57
- public function detailAction (string $ id )
62
+ public function detailAction (string $ id ): ResponseInterface
58
63
{
59
64
$ arguments = $ this ->searchProvider ->getRequestArguments ();
60
65
$ detail = $ this ->searchProvider ->getDocumentById ($ id );
61
-
62
66
if ($ this ->request ->hasArgument ('underlyingQuery ' )) {
63
67
$ underlyingQueryInfo = $ this ->request ->getArgument ('underlyingQuery ' );
64
- $ this ->response ->addAdditionalHeaderData (
65
- FrontendUtility::addQueryInformationAsJavaScript (
66
- $ underlyingQueryInfo ['q ' ],
67
- $ this ->settings ,
68
- (int ) $ underlyingQueryInfo ['position ' ],
69
- $ arguments
70
- )
68
+ $ underlyingQueryScriptTagContent = FrontendUtility::addQueryInformationAsJavaScript (
69
+ $ underlyingQueryInfo ['q ' ],
70
+ $ this ->settings ,
71
+ (int ) $ underlyingQueryInfo ['position ' ],
72
+ $ arguments
71
73
);
74
+
75
+ GeneralUtility::makeInstance (AssetCollector::class)
76
+ ->addInlineJavaScript ('underlyingQueryVar ' , $ underlyingQueryScriptTagContent , ['type ' => 'text/javascript ' ], ['priority ' => true ]);
72
77
}
73
78
74
79
$ this ->addStandardAssignments ();
@@ -78,43 +83,49 @@ public function detailAction(string $id)
78
83
'arguments ' => $ arguments ,
79
84
'config ' => $ this ->searchProvider ->getConfiguration (),
80
85
]);
86
+
87
+ return $ this ->htmlResponse ();
81
88
}
82
89
83
90
/**
84
91
* Index Action.
85
92
*/
86
- public function indexAction ()
93
+ public function indexAction (): ResponseInterface
87
94
{
88
95
if (array_key_exists ('id ' , $ this ->requestArguments )) {
89
- $ this ->forward ('detail ' );
90
- } else {
91
- $ this ->searchProvider ->setCounter ();
92
- $ this ->response ->addAdditionalHeaderData (
93
- FrontendUtility::addQueryInformationAsJavaScript (
94
- $ this ->searchProvider ->getRequestArguments ()['q ' ],
95
- $ this ->settings ,
96
- null ,
97
- $ this ->searchProvider ->getRequestArguments ()
98
- )
99
- );
96
+ return new ForwardResponse ('detail ' );
97
+ }
100
98
101
- $ this ->addStandardAssignments ();
102
- $ defaultQuery = $ this ->searchProvider ->getDefaultQuery ();
99
+ $ this ->searchProvider ->setCounter ();
103
100
104
- $ viewValues = [
105
- 'arguments ' => $ this ->searchProvider ->getRequestArguments (),
106
- 'config ' => $ this ->searchProvider ->getConfiguration (),
107
- ];
101
+ $ underlyingQueryScriptTagContent = FrontendUtility::addQueryInformationAsJavaScript (
102
+ $ this ->searchProvider ->getRequestArguments ()['q ' ] ?? [],
103
+ $ this ->settings ,
104
+ null ,
105
+ $ this ->searchProvider ->getRequestArguments ()
106
+ );
108
107
109
- CoreArrayUtility::mergeRecursiveWithOverrule ($ viewValues , $ defaultQuery );
110
- $ this ->view ->assignMultiple ($ viewValues );
111
- }
108
+ GeneralUtility::makeInstance (AssetCollector::class)
109
+ ->addInlineJavaScript ('underlyingQueryVar ' , $ underlyingQueryScriptTagContent , ['type ' => 'text/javascript ' ], ['priority ' => true ]);
110
+
111
+ $ this ->addStandardAssignments ();
112
+ $ defaultQuery = $ this ->searchProvider ->getDefaultQuery ();
113
+
114
+ $ viewValues = [
115
+ 'arguments ' => $ this ->searchProvider ->getRequestArguments (),
116
+ 'config ' => $ this ->searchProvider ->getConfiguration (),
117
+ ];
118
+
119
+ CoreArrayUtility::mergeRecursiveWithOverrule ($ viewValues , $ defaultQuery );
120
+ $ this ->view ->assignMultiple ($ viewValues );
121
+
122
+ return $ this ->htmlResponse ();
112
123
}
113
124
114
125
/**
115
126
* Initialisation and setup.
116
127
*/
117
- protected function initializeAction ()
128
+ protected function initializeAction (): void
118
129
{
119
130
ksort ($ this ->settings ['queryFields ' ]);
120
131
@@ -131,16 +142,18 @@ protected function initializeAction()
131
142
/**
132
143
* Suggest/Autocomplete action.
133
144
*/
134
- public function suggestAction ()
145
+ public function suggestAction (): ResponseInterface
135
146
{
136
147
$ results = $ this ->searchProvider ->suggestQuery ($ this ->searchProvider ->getRequestArguments ());
137
148
$ this ->view ->assign ('suggestions ' , $ results );
149
+
150
+ return $ this ->htmlResponse ();
138
151
}
139
152
140
153
/**
141
154
* Assigns standard variables to the view.
142
155
*/
143
- protected function addStandardAssignments ()
156
+ protected function addStandardAssignments (): void
144
157
{
145
158
$ this ->searchProvider ->setConfigurationValue ('extendedSearch ' , $ this ->searchProvider ->isExtendedSearch ());
146
159
$ this ->searchProvider ->setConfigurationValue (
@@ -154,7 +167,7 @@ protected function addStandardAssignments()
154
167
/**
155
168
* @param string $activeConnection
156
169
*/
157
- protected function initializeConnection ($ activeConnection )
170
+ protected function initializeConnection ($ activeConnection ): void
158
171
{
159
172
$ connectionConfiguration = $ this ->settings ['connections ' ][$ activeConnection ];
160
173
0 commit comments