17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
40 public function searchAction(ServerRequestInterface $request): ResponseInterface
42 $parsedBody = $request->getParsedBody();
44 $search = $parsedBody[
'value'] ??
null;
45 $tableName = $parsedBody[
'tableName'] ??
null;
46 $fieldName = $parsedBody[
'fieldName'] ??
null;
47 $uid = $parsedBody[
'uid'] ??
null;
48 $pid = isset($parsedBody[
'pid']) ? (int)$parsedBody[
'pid'] : 0;
49 $dataStructureIdentifier =
'' ??
null;
50 if (!empty($parsedBody[
'dataStructureIdentifier'])) {
51 $dataStructureIdentifier = $parsedBody[
'dataStructureIdentifier'];
53 $flexFormSheetName = $parsedBody[
'flexFormSheetName'] ??
null;
54 $flexFormFieldName = $parsedBody[
'flexFormFieldName'] ??
null;
55 $flexFormContainerName = $parsedBody[
'flexFormContainerName'] ??
null;
56 $flexFormContainerFieldName = $parsedBody[
'flexFormContainerFieldName'] ??
null;
59 if (empty($dataStructureIdentifier)) {
61 $fieldConfig =
$GLOBALS[
'TCA'][$tableName][
'columns'][$fieldName][
'config'];
62 $fieldNameInPageTsConfig = $fieldName;
65 $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
66 $dataStructure = $flexFormTools->parseDataStructureByIdentifier($dataStructureIdentifier);
67 if (empty($flexFormContainerFieldName)) {
69 $fieldNameInPageTsConfig = $flexFormFieldName;
70 if (!isset($dataStructure[
'sheets'][$flexFormSheetName][
'ROOT']
71 [
'el'][$flexFormFieldName][
'TCEforms'][
'config'])
73 throw new \RuntimeException(
74 'Specified path ' . $flexFormFieldName .
' not found in flex form data structure',
78 $fieldConfig = $dataStructure[
'sheets'][$flexFormSheetName][
'ROOT']
79 [
'el'][$flexFormFieldName][
'TCEforms'][
'config'];
81 $fieldNameInPageTsConfig = $flexFormContainerFieldName;
82 if (!isset($dataStructure[
'sheets'][$flexFormSheetName][
'ROOT']
83 [
'el'][$flexFormFieldName]
84 [
'el'][$flexFormContainerName]
85 [
'el'][$flexFormContainerFieldName][
'TCEforms'][
'config'])
87 throw new \RuntimeException(
88 'Specified path ' . $flexFormContainerName .
' not found in flex form section container data structure',
92 $fieldConfig = $dataStructure[
'sheets'][$flexFormSheetName][
'ROOT']
93 [
'el'][$flexFormFieldName]
94 [
'el'][$flexFormContainerName]
95 [
'el'][$flexFormContainerFieldName][
'TCEforms'][
'config'];
101 $wizardConfig = $fieldConfig[
'suggestOptions'] ?? [];
110 foreach ($queryTables as $queryTable) {
112 if (!is_array(
$GLOBALS[
'TCA'][$queryTable]) || empty(
$GLOBALS[
'TCA'][$queryTable])) {
116 $config = $this->
getConfigurationForTable($queryTable, $wizardConfig, $pageTsConfig, $tableName, $fieldNameInPageTsConfig);
119 if (!isset($config[
'addWhere']) && $whereClause) {
120 $config[
'addWhere'] = $whereClause;
122 if (isset($config[
'addWhere'])) {
124 '###THIS_UID###' => (int)$uid,
125 '###CURRENT_PID###' => (
int)$pid
127 if (isset($pageTsConfig[
'TCEFORM.'][$tableName .
'.'][$fieldNameInPageTsConfig .
'.'])) {
128 $fieldTSconfig = $pageTsConfig[
'TCEFORM.'][$tableName .
'.'][$fieldNameInPageTsConfig .
'.'];
129 if (isset($fieldTSconfig[
'PAGE_TSCONFIG_ID'])) {
130 $replacement[
'###PAGE_TSCONFIG_ID###'] = (int)$fieldTSconfig[
'PAGE_TSCONFIG_ID'];
132 if (isset($fieldTSconfig[
'PAGE_TSCONFIG_IDLIST'])) {
133 $replacement[
'###PAGE_TSCONFIG_IDLIST###'] = implode(
',', GeneralUtility::intExplode(
',', $fieldTSconfig[
'PAGE_TSCONFIG_IDLIST']));
135 if (isset($fieldTSconfig[
'PAGE_TSCONFIG_STR'])) {
136 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($fieldConfig[
'foreign_table']);
139 $replacement[
'###PAGE_TSCONFIG_STR###'] = trim($connection->quote($fieldTSconfig[
'PAGE_TSCONFIG_STR']),
'\'');
142 $config[
'addWhere'] = strtr(
' ' . $config[
'addWhere'], $replacement);
146 $receiverClassName = $config[
'receiverClass'];
147 if (!class_exists($receiverClassName)) {
148 $receiverClassName = SuggestWizardDefaultReceiver::class;
150 $receiverObj = GeneralUtility::makeInstance($receiverClassName, $queryTable, $config);
155 $rows = $receiverObj->queryTable($params);
159 $resultRows = $rows + $resultRows;
164 $maxItems = $config[
'maxItemsInResultList'] ?? 10;
165 $maxItems = min(count($resultRows), $maxItems);
167 array_splice($resultRows, $maxItems);
168 return (
new JsonResponse())->setPayload(array_values($resultRows));
179 return (
bool)$tableConfig[
'ctrl'][
'hideTable'];
196 if ($tableConfig[
'ctrl'][
'adminOnly']) {
201 return !$tableConfig[
'ctrl'][
'rootLevel'] || $tableConfig[
'ctrl'][
'security'][
'ignoreRootLevelRestriction'];
217 $config = (array)$wizardConfig[
'default'];
219 if (is_array($wizardConfig[$queryTable])) {
222 $globalSuggestTsConfig = $TSconfig[
'TCEFORM.'][
'suggest.'];
223 $currentFieldSuggestTsConfig = $TSconfig[
'TCEFORM.'][$table .
'.'][$field .
'.'][
'suggest.'];
227 if (is_array($globalSuggestTsConfig[
'default.'])) {
231 if (is_array($globalSuggestTsConfig[$queryTable .
'.'])) {
237 if (is_array($currentFieldSuggestTsConfig[
'default.'])) {
241 if (is_array($currentFieldSuggestTsConfig[$queryTable .
'.'])) {
259 if (isset($fieldConfig[
'allowed'])) {
260 if ($fieldConfig[
'allowed'] !==
'*') {
262 $queryTables = GeneralUtility::trimExplode(
',', $fieldConfig[
'allowed']);
265 foreach (
$GLOBALS[
'TCA'] as $tableName => $tableConfig) {
267 $queryTables[] = $tableName;
270 unset($tableName, $tableConfig);
272 } elseif (isset($fieldConfig[
'foreign_table'])) {
274 $queryTables = [$fieldConfig[
'foreign_table']];
290 if (!isset($fieldConfig[
'foreign_table'])) {
295 return trim(preg_replace(
'/ORDER[[:space:]]+BY.*/i',
'', $fieldConfig[
'foreign_table_where']));