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