‪TYPO3CMS  10.4
AutocompleteController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
26 {
27  public function ‪__construct()
28  {
29  trigger_error(__CLASS__ . ' will be removed in TYPO3 v11.', E_USER_DEPRECATED);
30  }
31 
35  public function ‪indexAction()
36  {
37  $this->view->assign('id', $this->widgetConfiguration['for']);
38  }
39 
44  public function ‪autocompleteAction($term)
45  {
46  $searchProperty = $this->widgetConfiguration['searchProperty'];
47  $query = $this->widgetConfiguration['objects']->getQuery();
48  $constraint = $query->getConstraint();
49  if ($constraint !== null) {
50  $query->matching($query->logicalAnd($constraint, $query->like($searchProperty, '%' . $term . '%', false)));
51  } else {
52  $query->matching($query->like($searchProperty, '%' . $term . '%', false));
53  }
54  $results = $query->execute();
55  ‪$output = [];
56  foreach ($results as $singleResult) {
57  $val = ‪ObjectAccess::getProperty($singleResult, $searchProperty);
58  ‪$output[] = [
59  'id' => $val,
60  'label' => $val,
61  'value' => $val
62  ];
63  }
64  return json_encode(‪$output);
65  }
66 }
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller
Definition: AutocompleteController.php:16
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:38
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController\autocompleteAction
‪string autocompleteAction($term)
Definition: AutocompleteController.php:44
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController\__construct
‪__construct()
Definition: AutocompleteController.php:27
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController\indexAction
‪indexAction()
Definition: AutocompleteController.php:35
‪TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
Definition: AbstractWidgetController.php:32
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\AutocompleteController
Definition: AutocompleteController.php:26
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getProperty
‪static mixed getProperty($subject, string $propertyName, bool $forceDirectAccess=false)
Definition: ObjectAccess.php:62