|
1
|
|
|
<?php |
|
2
|
|
|
namespace TYPO3\CMS\Fluid\ViewHelpers\Widget; |
|
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
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Simple autocomplete widget. |
|
20
|
|
|
* |
|
21
|
|
|
* .. note:: |
|
22
|
|
|
* Make sure to include jQuery and jQuery UI in the HTML, like that:: |
|
23
|
|
|
* |
|
24
|
|
|
* <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> |
|
25
|
|
|
* <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script> |
|
26
|
|
|
* <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" media="all" /> |
|
27
|
|
|
* <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" /> |
|
28
|
|
|
* |
|
29
|
|
|
* You can include the provided TypoScript template that includes the above snippet to the pages headerData. |
|
30
|
|
|
* |
|
31
|
|
|
* Examples |
|
32
|
|
|
* ======== |
|
33
|
|
|
* |
|
34
|
|
|
* Render lib object:: |
|
35
|
|
|
* |
|
36
|
|
|
* <input type="text" id="name" /> |
|
37
|
|
|
* <f:widget.autocomplete for="name" objects="{posts}" searchProperty="author" storeSession="false"> |
|
38
|
|
|
* |
|
39
|
|
|
* Output:: |
|
40
|
|
|
* |
|
41
|
|
|
* <input type="text" id="name" /> |
|
42
|
|
|
* |
|
43
|
|
|
* The input field and the required JavaScript for the Ajax communication. |
|
44
|
|
|
* The storeSession attribute can be used in any widget |
|
45
|
|
|
* and will prevent cookie creation / session storage for the widget. |
|
46
|
|
|
* See Resources/Private/Templates/ViewHelpers/Widget/Autocomplete/Index.html |
|
47
|
|
|
* @deprecated since TYPO3 v10.4, will be removed in TYPO3 v11.0. |
|
48
|
|
|
*/ |
|
49
|
|
|
class AutocompleteViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper |
|
50
|
|
|
{ |
|
51
|
|
|
/** |
|
52
|
|
|
* @var bool |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $ajaxWidget = true; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var \TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $controller; |
|
60
|
|
|
|
|
61
|
|
|
public function __construct() |
|
62
|
|
|
{ |
|
63
|
|
|
trigger_error(__CLASS__ . ' will be removed in TYPO3 v11.', E_USER_DEPRECATED); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Initialize arguments |
|
68
|
|
|
*/ |
|
69
|
|
|
public function initializeArguments() |
|
70
|
|
|
{ |
|
71
|
|
|
parent::initializeArguments(); |
|
72
|
|
|
$this->registerArgument('objects', QueryResultInterface::class, 'Objects to auto-complete', true); |
|
73
|
|
|
$this->registerArgument('for', 'string', 'Property to fill', true); |
|
74
|
|
|
$this->registerArgument('searchProperty', 'string', 'Property to search within when filtering list', true); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param \TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController $controller |
|
79
|
|
|
*/ |
|
80
|
|
|
public function injectAutocompleteController(\TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController $controller) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->controller = $controller; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function render() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->initiateSubRequest(); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|