[TASK] Streamline PHPDoc comment matches function/method signature
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / Classes / Example / PluginHook.php
1 <?php
2 namespace TYPO3\CMS\IndexedSearch\Example;
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 /**
18 * Index search frontend example hook
19 */
20 /**
21 * Index search frontend - EXAMPLE hook for alternative searching / display etc.
22 * Hooks are configured in ext_localconf.php as key => hook-reference pairs in $TYPO3_CONF_VARS['EXTCONF']['indexed_search']['pi1_hooks']. See example in ext_localconf.php for "indexed_search"
23 * Each hook must have an entry, the key must match the hook-key in class.tx_indexed_search.php and generally the key equals the function name in the hook object (a convension used)
24 */
25 class PluginHook
26 {
27 /**
28 * Is set to a reference to the parent object, "pi1/class.indexedsearch.php"
29 *
30 * @var \TYPO3\CMS\IndexedSearch\Controller\SearchFormController
31 */
32 public $pObj;
33
34 /**
35 * EXAMPLE of how you can post process the initialized values in the frontend plugin.
36 * The example reverses the order of elements in the ranking selector box. You can modify other values like this or add / remove items.
37 *
38 * This hook is activated by this key / value pair in ext_localconf.php
39 * 'initialize_postProc' => \TYPO3\CMS\IndexedSearch\Example\PluginHook::class,
40 */
41 public function initialize_postProc()
42 {
43 $this->pObj->optValues['order'] = array_reverse($this->pObj->optValues['order']);
44 }
45
46 /**
47 * Example of how the content displayed in the result rows can be extended or modified
48 * before the data is assigned to the fluid template as {resultsets}.
49 * The code example replaces all occurrences of the search string with the replacement
50 * string in the description of all rows in the result.
51 *
52 * @param array $result
53 * @return array
54 */
55 public function getDisplayResults_postProc(array $result): array
56 {
57 if ($result['count'] > 0) {
58 foreach ($result['rows'] as $rowIndex => $row) {
59 $result['rows'][$rowIndex]['description'] = \str_replace('foo', 'bar', $row['description']);
60 }
61 }
62 return $result;
63 }
64
65 /**
66 * Providing an alternative search algorithm!
67 *
68 * @param array $sWArr Array of search words
69 */
70 public function getResultRows($sWArr)
71 {
72 }
73
74 /**
75 * Example of how the content displayed in the result rows can be post processed before rendered into HTML.
76 * This example simply shows how the description field is wrapped in italics and the path is hidden by setting it blank.
77 *
78 * @param array $tmplContent Template Content (generated from result row) being processed.
79 * @param array $row Result row
80 * @param bool $headerOnly If set, the result row is a sub-row.
81 * @return array Template Content returned.
82 */
83 public function prepareResultRowTemplateData_postProc($tmplContent, $row, $headerOnly)
84 {
85 $tmplContent['description'] = '<em>' . $tmplContent['description'] . '</em>';
86 $tmplContent['path'] = '';
87 return $tmplContent;
88 }
89 }