2 declare(strict_types = 1);
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
63 public function suggestAction(ServerRequestInterface $request): ResponseInterface
67 $queryParameters = $request->getParsedBody() ?? [];
68 $values = $queryParameters[
'values'];
69 $mode = $queryParameters[
'mode'];
70 $tableName = $queryParameters[
'tableName'];
71 $pid = (int)$queryParameters[
'pageId'];
72 $parentPageId = (int)$queryParameters[
'parentPageId'];
73 $recordId = (int)$queryParameters[
'recordId'];
74 $languageId = (int)$queryParameters[
'language'];
75 $fieldName = $queryParameters[
'fieldName'];
77 $fieldConfig =
$GLOBALS[
'TCA'][$tableName][
'columns'][$fieldName][
'config'] ?? [];
80 $columnsOverridesConfigOfField =
$GLOBALS[
'TCA'][$tableName][
'types'][$recordType][
'columnsOverrides'][$fieldName][
'config'] ??
null;
81 if ($columnsOverridesConfigOfField) {
84 if (empty($fieldConfig)) {
85 throw new \RuntimeException(
86 'No valid field configuration for table ' . $tableName .
' field name ' . $fieldName .
' found.',
91 $evalInfo = !empty($fieldConfig[
'eval']) ? GeneralUtility::trimExplode(
',', $fieldConfig[
'eval'],
true) : [];
92 $hasToBeUniqueInDb = in_array(
'unique', $evalInfo,
true);
93 $hasToBeUniqueInSite = in_array(
'uniqueInSite', $evalInfo,
true);
94 $hasToBeUniqueInPid = in_array(
'uniqueInPid', $evalInfo,
true);
98 $recordData = $values;
99 if (!isset($recordData[
'uid'])) {
100 $recordData[
'uid'] = $recordId;
102 $recordData[
'pid'] = $pid;
103 if (!empty(
$GLOBALS[
'TCA'][$tableName][
'ctrl'][
'languageField'])) {
104 $recordData[
$GLOBALS[
'TCA'][$tableName][
'ctrl'][
'languageField']] = $languageId;
106 if ($tableName ===
'pages' && empty($recordData[
'is_siteroot'])) {
107 $recordData[
'is_siteroot'] = $row[
'is_siteroot'];
110 $slug = GeneralUtility::makeInstance(SlugHelper::class, $tableName, $fieldName, $fieldConfig);
111 if ($mode ===
'auto') {
113 $proposal = $slug->generate($recordData, $pid);
114 } elseif ($mode ===
'recreate') {
115 $proposal = $slug->generate($recordData, $parentPageId);
116 } elseif ($mode ===
'manual') {
118 $proposal = $slug->sanitize($values[
'manual']);
120 throw new \RuntimeException(
'mode must be either "auto", "recreate" or "manual"', 1535835666);
124 ->fromArray($recordData, $pid, $recordId);
125 if ($hasToBeUniqueInDb && !$slug->isUniqueInTable($proposal, $state)) {
127 $proposal = $slug->buildSlugForUniqueInTable($proposal, $state);
129 if ($hasToBeUniqueInSite && !$slug->isUniqueInSite($proposal, $state)) {
131 $proposal = $slug->buildSlugForUniqueInSite($proposal, $state);
133 if ($hasToBeUniqueInPid && !$slug->isUniqueInPid($proposal, $state)) {
135 $proposal = $slug->buildSlugForUniqueInPid($proposal, $state);
139 'hasConflicts' => !$mode && $hasConflict,
140 'manual' => $values[
'manual'] ??
'',
141 'proposal' => $proposal,
152 $queryParameters = $request->getParsedBody() ?? [];
153 $expectedHash = GeneralUtility::hmac(
157 $queryParameters[
'tableName'],
158 $queryParameters[
'pageId'],
159 $queryParameters[
'recordId'],
160 $queryParameters[
'language'],
161 $queryParameters[
'fieldName'],
162 $queryParameters[
'command'],
163 $queryParameters[
'parentPageId'],
168 if (!hash_equals($expectedHash, $queryParameters[
'signature'])) {
169 throw new \InvalidArgumentException(
170 'HMAC could not be verified',