‪TYPO3CMS  9.5
EditController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
28 
34 {
36 
42  protected ‪$deprecatedPublicProperties = [
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.',
45  ];
46 
62  protected ‪$P;
63 
69  protected ‪$doClose;
70 
76  protected ‪$closeWindow = '<script language="javascript" type="text/javascript">close();</script>';
77 
81  public function ‪__construct()
82  {
83  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_wizards.xlf');
84 
85  // @deprecated since TYPO3 v9, will be moved out of __construct() in TYPO3 v10.0
86  $this->‪init(‪$GLOBALS['TYPO3_REQUEST']);
87  }
88 
94  protected function ‪init(ServerRequestInterface $request)
95  {
96  $parsedBody = $request->getParsedBody();
97  $queryParams = $request->getQueryParams();
98 
99  $this->P = $parsedBody['P'] ?? $queryParams['P'] ?? [];
100 
101  // Used for the return URL to FormEngine so that we can close the window.
102  $this->doClose = $parsedBody['doClose'] ?? $queryParams['doClose'] ?? 0;
103  }
104 
112  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
113  {
114  $content = $this->‪processRequest($request);
115  return $content;
116  }
117 
126  public function ‪main()
127  {
128  trigger_error('EditController->main() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
129  $request = ‪$GLOBALS['TYPO3_REQUEST'];
130 
131  $response = $this->‪processRequest($request);
132 
133  if ($response instanceof RedirectResponse) {
134  ‪HttpUtility::redirect($response->getHeaders()['location'][0]);
135  } else {
136  return $response->getBody()->getContents();
137  }
138  }
139 
148  protected function ‪processRequest(ServerRequestInterface $request): ResponseInterface
149  {
150  if ($this->doClose) {
151  return new HtmlResponse($this->closeWindow);
152  }
153  // Initialize:
154  $table = $this->P['table'];
155  $field = $this->P['field'];
156 
157  if (empty($this->P['flexFormDataStructureIdentifier'])) {
158  // If there is not flex data structure identifier, field config is found in globals
159  $config = ‪$GLOBALS['TCA'][$table]['columns'][$field]['config'];
160  } else {
161  // If there is a flex data structure identifier, parse that data structure and
162  // fetch config defined by given flex path
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'],
170  1537356346
171  );
172  }
173  }
174 
175  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
176  $urlParameters = [
177  'returnUrl' => (string)$uriBuilder->buildUriFromRoute('wizard_edit', ['doClose' => 1])
178  ];
179 
180  // Detecting the various allowed field type setups and acting accordingly.
181  if (is_array($config)
182  && $config['type'] === 'select'
183  && !$config['MM']
184  && $config['maxitems'] <= 1
185  && ‪MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
186  && $this->P['currentValue']
187  && $config['foreign_table']
188  ) {
189  // SINGLE value
190  $urlParameters['edit[' . $config['foreign_table'] . '][' . $this->P['currentValue'] . ']'] = 'edit';
191  // Redirect to FormEngine
192  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
193  return new RedirectResponse($url);
194  }
195 
196  if (is_array($config)
197  && $this->P['currentSelectedValues']
198  && (
199  $config['type'] === 'select'
200  && $config['foreign_table']
201  || $config['type'] === 'group'
202  && $config['internal_type'] === 'db'
203  )
204  ) {
205  // MULTIPLE VALUES:
206  // Init settings:
207  $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table'];
208  $prependName = 1;
209  // Selecting selected values into an array:
210  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
211  $relationHandler->start($this->P['currentSelectedValues'], $allowedTables);
212  $value = $relationHandler->getValueArray($prependName);
213  // Traverse that array and make parameters for FormEngine
214  foreach ($value as $rec) {
215  $recTableUidParts = GeneralUtility::revExplode('_', $rec, 2);
216  $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit';
217  }
218  // Redirect to FormEngine
219  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
220 
221  return new RedirectResponse($url);
222  }
223  return new HtmlResponse($this->closeWindow);
224  }
225 }
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$doClose
‪int $doClose
Definition: EditController.php:65
‪TYPO3\CMS\Backend\Controller\Wizard\AbstractWizardController\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractWizardController.php:77
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\__construct
‪__construct()
Definition: EditController.php:76
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:32
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\init
‪init(ServerRequestInterface $request)
Definition: EditController.php:89
‪TYPO3
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$closeWindow
‪string $closeWindow
Definition: EditController.php:71
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: EditController.php:107
‪TYPO3\CMS\Backend\Controller\Wizard\AbstractWizardController
Definition: AbstractWizardController.php:28
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: EditController.php:40
‪TYPO3\CMS\Backend\Controller\Wizard
Definition: AbstractWizardController.php:2
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\processRequest
‪ResponseInterface processRequest(ServerRequestInterface $request)
Definition: EditController.php:143
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:36
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Backend\Controller\Wizard\EditController
Definition: EditController.php:34
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:21
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$P
‪array $P
Definition: EditController.php:59
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\HttpUtility\redirect
‪static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:103
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\main
‪string main()
Definition: EditController.php:121
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25