2 declare(strict_types = 1);
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
43 'P' =>
'Using $P of class EditController from the outside is discouraged, as this variable is only used for internal storage.',
44 'doClose' =>
'Using $doClose of class EditController from the outside is discouraged, as this variable is only used for internal storage.',
76 protected $closeWindow =
'<script language="javascript" type="text/javascript">close();</script>';
94 protected function init(ServerRequestInterface $request)
96 $parsedBody = $request->getParsedBody();
97 $queryParams = $request->getQueryParams();
99 $this->P = $parsedBody[
'P'] ?? $queryParams[
'P'] ?? [];
102 $this->doClose = $parsedBody[
'doClose'] ?? $queryParams[
'doClose'] ?? 0;
112 public function mainAction(ServerRequestInterface $request): ResponseInterface
126 public function main()
128 trigger_error(
'EditController->main() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
133 if ($response instanceof RedirectResponse) {
136 return $response->getBody()->getContents();
148 protected function processRequest(ServerRequestInterface $request): ResponseInterface
150 if ($this->doClose) {
151 return new HtmlResponse($this->closeWindow);
154 $table = $this->P[
'table'];
155 $field = $this->P[
'field'];
157 if (empty($this->P[
'flexFormDataStructureIdentifier'])) {
159 $config =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
163 $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
164 $dataStructure = $flexFormTools->parseDataStructureByIdentifier($this->P[
'flexFormDataStructureIdentifier']);
165 $config = $flexFormTools->getArrayValueByPath($this->P[
'flexFormDataStructurePath'], $dataStructure);
166 if (!is_array($config)) {
167 throw new \RuntimeException(
168 'Something went wrong finding flex path ' . $this->P[
'flexFormDataStructurePath']
169 .
' in data structure identified by ' . $this->P[
'flexFormDataStructureIdentifier'],
175 $uriBuilder = GeneralUtility::makeInstance(\
TYPO3\CMS\Backend\Routing\UriBuilder::class);
177 'returnUrl' => (string)$uriBuilder->buildUriFromRoute(
'wizard_edit', [
'doClose' => 1])
181 if (is_array($config)
182 && $config[
'type'] ===
'select'
184 && $config[
'maxitems'] <= 1
186 && $this->P[
'currentValue']
187 && $config[
'foreign_table']
190 $urlParameters[
'edit[' . $config[
'foreign_table'] .
'][' . $this->P[
'currentValue'] .
']'] =
'edit';
192 $url = (string)$uriBuilder->buildUriFromRoute(
'record_edit', $urlParameters);
193 return new RedirectResponse($url);
196 if (is_array($config)
197 && $this->P[
'currentSelectedValues']
199 $config[
'type'] ===
'select'
200 && $config[
'foreign_table']
201 || $config[
'type'] ===
'group'
202 && $config[
'internal_type'] ===
'db'
207 $allowedTables = $config[
'type'] ===
'group' ? $config[
'allowed'] : $config[
'foreign_table'];
210 $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
211 $relationHandler->start($this->P[
'currentSelectedValues'], $allowedTables);
212 $value = $relationHandler->getValueArray($prependName);
214 foreach ($value as $rec) {
215 $recTableUidParts = GeneralUtility::revExplode(
'_', $rec, 2);
216 $urlParameters[
'edit[' . $recTableUidParts[0] .
'][' . $recTableUidParts[1] .
']'] =
'edit';
219 $url = (string)$uriBuilder->buildUriFromRoute(
'record_edit', $urlParameters);
221 return new RedirectResponse($url);
223 return new HtmlResponse($this->closeWindow);