‪TYPO3CMS  10.4
EditController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
29 
35 {
51  protected ‪$P;
52 
58  protected ‪$doClose;
59 
65  protected ‪$closeWindow = '<script>close();</script>';
66 
74  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
75  {
76  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_wizards.xlf');
77 
78  $parsedBody = $request->getParsedBody();
79  $queryParams = $request->getQueryParams();
80 
81  $this->P = $parsedBody['P'] ?? $queryParams['P'] ?? [];
82  // Used for the return URL to FormEngine so that we can close the window.
83  $this->doClose = $parsedBody['doClose'] ?? $queryParams['doClose'] ?? 0;
84 
85  return $this->‪processRequest();
86  }
87 
95  protected function ‪processRequest(): ResponseInterface
96  {
97  if ($this->doClose) {
98  return new ‪HtmlResponse($this->closeWindow);
99  }
100  // Initialize:
101  $table = $this->P['table'];
102  $field = $this->P['field'];
103 
104  if (empty($this->P['flexFormDataStructureIdentifier'])) {
105  // If there is not flex data structure identifier, field config is found in globals
106  $config = ‪$GLOBALS['TCA'][$table]['columns'][$field]['config'];
107  } else {
108  // If there is a flex data structure identifier, parse that data structure and
109  // fetch config defined by given flex path
110  $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
111  $dataStructure = $flexFormTools->parseDataStructureByIdentifier($this->P['flexFormDataStructureIdentifier']);
112  $config = $flexFormTools->getArrayValueByPath($this->P['flexFormDataStructurePath'], $dataStructure);
113  if (!is_array($config)) {
114  throw new \RuntimeException(
115  'Something went wrong finding flex path ' . $this->P['flexFormDataStructurePath']
116  . ' in data structure identified by ' . $this->P['flexFormDataStructureIdentifier'],
117  1537356346
118  );
119  }
120  }
121 
122  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
123  $urlParameters = [
124  'returnUrl' => (string)$uriBuilder->buildUriFromRoute('wizard_edit', ['doClose' => 1])
125  ];
126 
127  // Detecting the various allowed field type setups and acting accordingly.
128  if (is_array($config)
129  && $config['type'] === 'select'
130  && !$config['MM']
131  && $config['maxitems'] <= 1
132  && ‪MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
133  && $this->P['currentValue']
134  && $config['foreign_table']
135  ) {
136  // SINGLE value
137  $urlParameters['edit[' . $config['foreign_table'] . '][' . $this->P['currentValue'] . ']'] = 'edit';
138  // Redirect to FormEngine
139  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
140  return new ‪RedirectResponse($url);
141  }
142 
143  if (is_array($config)
144  && $this->P['currentSelectedValues']
145  && (
146  $config['type'] === 'select'
147  && $config['foreign_table']
148  || $config['type'] === 'group'
149  && $config['internal_type'] === 'db'
150  )
151  ) {
152  // MULTIPLE VALUES:
153  // Init settings:
154  $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table'];
155  // Selecting selected values into an array:
156  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
157  $relationHandler->start($this->P['currentSelectedValues'], $allowedTables);
158  $value = $relationHandler->getValueArray(true);
159  // Traverse that array and make parameters for FormEngine
160  foreach ($value as $rec) {
161  $recTableUidParts = ‪GeneralUtility::revExplode('_', $rec, 2);
162  $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit';
163  }
164  // Redirect to FormEngine
165  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
166 
167  return new ‪RedirectResponse($url);
168  }
169  return new ‪HtmlResponse($this->closeWindow);
170  }
171 }
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$doClose
‪int $doClose
Definition: EditController.php:56
‪TYPO3\CMS\Backend\Controller\Wizard\AbstractWizardController\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractWizardController.php:77
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\processRequest
‪ResponseInterface processRequest()
Definition: EditController.php:92
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:35
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$closeWindow
‪string $closeWindow
Definition: EditController.php:62
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: EditController.php:71
‪TYPO3\CMS\Backend\Controller\Wizard\AbstractWizardController
Definition: AbstractWizardController.php:28
‪TYPO3\CMS\Backend\Controller\Wizard
Definition: AbstractWizardController.php:16
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:38
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility\revExplode
‪static string[] revExplode($delimiter, $string, $count=0)
Definition: GeneralUtility.php:1025
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Backend\Controller\Wizard\EditController
Definition: EditController.php:35
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$P
‪array $P
Definition: EditController.php:50
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26