‪TYPO3CMS  11.5
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;
31 
37 {
38  protected const ‪JAVASCRIPT_HELPER = 'EXT:backend/Resources/Public/JavaScript/Helper.js';
39 
55  protected ‪$P;
56 
62  protected ‪$doClose;
63 
69  protected string ‪$closeWindow;
70 
71  public function ‪__construct()
72  {
73  $this->closeWindow = sprintf(
74  '<script %s></script>',
75  GeneralUtility::implodeAttributes([
77  GeneralUtility::getFileAbsFileName(self::JAVASCRIPT_HELPER)
78  ),
79  'data-action' => 'window.close',
80  ], true)
81  );
82  }
83 
91  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
92  {
93  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_wizards.xlf');
94 
95  $parsedBody = $request->getParsedBody();
96  $queryParams = $request->getQueryParams();
97 
98  $this->P = $parsedBody['P'] ?? $queryParams['P'] ?? [];
99  // Used for the return URL to FormEngine so that we can close the window.
100  $this->doClose = $parsedBody['doClose'] ?? $queryParams['doClose'] ?? 0;
101 
102  return $this->‪processRequest();
103  }
104 
112  protected function ‪processRequest(): ResponseInterface
113  {
114  if ($this->doClose) {
115  return new ‪HtmlResponse($this->closeWindow);
116  }
117  // Initialize:
118  $table = $this->P['table'];
119  $field = $this->P['field'];
120 
121  if (empty($this->P['flexFormDataStructureIdentifier'])) {
122  // If there is not flex data structure identifier, field config is found in globals
123  $config = ‪$GLOBALS['TCA'][$table]['columns'][$field]['config'];
124  } else {
125  // If there is a flex data structure identifier, parse that data structure and
126  // fetch config defined by given flex path
127  $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
128  $dataStructure = $flexFormTools->parseDataStructureByIdentifier($this->P['flexFormDataStructureIdentifier']);
129  $config = ‪ArrayUtility::getValueByPath($dataStructure, $this->P['flexFormDataStructurePath']);
130  if (!is_array($config)) {
131  throw new \RuntimeException(
132  'Something went wrong finding flex path ' . $this->P['flexFormDataStructurePath']
133  . ' in data structure identified by ' . $this->P['flexFormDataStructureIdentifier'],
134  1537356346
135  );
136  }
137  }
138 
139  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
140  $urlParameters = [
141  'returnUrl' => (string)$uriBuilder->buildUriFromRoute('wizard_edit', ['doClose' => 1]),
142  ];
143 
144  // Detecting the various allowed field type setups and acting accordingly.
145  if (is_array($config)
146  && $config['type'] === 'select'
147  && !($config['MM'] ?? false)
148  && (int)($config['maxitems'] ?? 0) <= 1
149  && ‪MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
150  && $this->P['currentValue']
151  && $config['foreign_table']
152  ) {
153  // SINGLE value
154  $urlParameters['edit[' . $config['foreign_table'] . '][' . $this->P['currentValue'] . ']'] = 'edit';
155  // Redirect to FormEngine
156  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
157  return new RedirectResponse($url);
158  }
159 
160  if (!empty($config['type'])
161  && !empty($this->P['currentSelectedValues'])
162  && (
163  $config['type'] === 'select' && !empty($config['foreign_table'])
164  || $config['type'] === 'group' && !empty($config['allowed'])
165  )
166  ) {
167  // MULTIPLE VALUES:
168  // Init settings:
169  $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table'];
170  // Selecting selected values into an array:
171  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
172  $relationHandler->start($this->P['currentSelectedValues'], $allowedTables);
173  $value = $relationHandler->getValueArray(true);
174  // Traverse that array and make parameters for FormEngine
175  foreach ($value as $rec) {
176  $recTableUidParts = ‪GeneralUtility::revExplode('_', $rec, 2);
177  $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit';
178  }
179  // Redirect to FormEngine
180  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
181 
182  return new RedirectResponse($url);
183  }
184  return new HtmlResponse($this->closeWindow);
185  }
186 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\revExplode
‪static list< string > revExplode($delimiter, $string, $count=0)
Definition: GeneralUtility.php:964
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$doClose
‪int $doClose
Definition: EditController.php:60
‪TYPO3\CMS\Backend\Controller\Wizard\AbstractWizardController\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractWizardController.php:76
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪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:110
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\__construct
‪__construct()
Definition: EditController.php:69
‪TYPO3\CMS\Core\Database\RelationHandler
Definition: RelationHandler.php:37
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\JAVASCRIPT_HELPER
‪const JAVASCRIPT_HELPER
Definition: EditController.php:38
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$closeWindow
‪string $closeWindow
Definition: EditController.php:67
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: EditController.php:89
‪TYPO3\CMS\Backend\Controller\Wizard\AbstractWizardController
Definition: AbstractWizardController.php:28
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:180
‪TYPO3\CMS\Backend\Controller\Wizard
Definition: AbstractWizardController.php:16
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:40
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Backend\Controller\Wizard\EditController
Definition: EditController.php:37
‪TYPO3\CMS\Backend\Controller\Wizard\EditController\$P
‪array $P
Definition: EditController.php:54
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef)
Definition: LanguageService.php:271
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26