|
1
|
|
|
<?php |
|
2
|
|
|
namespace TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller; |
|
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
|
|
|
* Class AutocompleteController |
|
19
|
|
|
* @deprecated since TYPO3 v10.4, will be removed in TYPO3 v11.0. |
|
20
|
|
|
*/ |
|
21
|
|
|
class AutocompleteController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController |
|
22
|
|
|
{ |
|
23
|
|
|
public function __construct() |
|
24
|
|
|
{ |
|
25
|
|
|
trigger_error(__CLASS__ . ' will be removed in TYPO3 v11.', E_USER_DEPRECATED); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Simply assigns the ID of the widget. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function indexAction() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->view->assign('id', $this->widgetConfiguration['for']); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $term |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function autocompleteAction($term) |
|
41
|
|
|
{ |
|
42
|
|
|
$searchProperty = $this->widgetConfiguration['searchProperty']; |
|
43
|
|
|
$query = $this->widgetConfiguration['objects']->getQuery(); |
|
44
|
|
|
$constraint = $query->getConstraint(); |
|
45
|
|
|
if ($constraint !== null) { |
|
46
|
|
|
$query->matching($query->logicalAnd($constraint, $query->like($searchProperty, '%' . $term . '%', false))); |
|
47
|
|
|
} else { |
|
48
|
|
|
$query->matching($query->like($searchProperty, '%' . $term . '%', false)); |
|
49
|
|
|
} |
|
50
|
|
|
$results = $query->execute(); |
|
51
|
|
|
$output = []; |
|
52
|
|
|
foreach ($results as $singleResult) { |
|
53
|
|
|
$val = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($singleResult, $searchProperty); |
|
54
|
|
|
$output[] = [ |
|
55
|
|
|
'id' => $val, |
|
56
|
|
|
'label' => $val, |
|
57
|
|
|
'value' => $val |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
return json_encode($output); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|