[TASK] Create own response instance in controller actions
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / ListController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\Wizard;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Http\HtmlResponse;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Utility\HttpUtility;
23
24 /**
25 * Script Class for redirecting the user to the Web > List module if a wizard-link has been clicked in FormEngine
26 */
27 class ListController extends AbstractWizardController
28 {
29 /**
30 * @var int
31 */
32 public $pid;
33
34 /**
35 * Wizard parameters, coming from FormEngine linking to the wizard.
36 *
37 * @var array
38 */
39 public $P;
40
41 /**
42 * Table to show, if none, then all tables are listed in list module.
43 *
44 * @var string
45 */
46 public $table;
47
48 /**
49 * Page id to list.
50 *
51 * @var string
52 */
53 public $id;
54
55 /**
56 * Initialization of the class, setting GPvars.
57 */
58 public function __construct()
59 {
60 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_wizards.xlf');
61 $GLOBALS['SOBE'] = $this;
62 $this->P = GeneralUtility::_GP('P');
63 $this->table = GeneralUtility::_GP('table');
64 $this->id = GeneralUtility::_GP('id');
65 }
66
67 /**
68 * Injects the request object for the current request or subrequest
69 * As this controller goes only through the main() method, it is rather simple for now
70 *
71 * @param ServerRequestInterface $request
72 * @return ResponseInterface
73 */
74 public function mainAction(ServerRequestInterface $request): ResponseInterface
75 {
76 $this->main();
77 return new HtmlResponse('');
78 }
79
80 /**
81 * Main function
82 * Will issue a location-header, redirecting either BACK or to a new FormEngine instance...
83 */
84 public function main()
85 {
86 // Get this record
87 $origRow = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
88 // Get TSconfig for it.
89 $TSconfig = BackendUtility::getTCEFORM_TSconfig(
90 $this->table,
91 is_array($origRow) ? $origRow : ['pid' => $this->P['pid']]
92 );
93 // Set [params][pid]
94 if (substr($this->P['params']['pid'], 0, 3) === '###' && substr($this->P['params']['pid'], -3) === '###') {
95 $keyword = substr($this->P['params']['pid'], 3, -3);
96 if (strpos($keyword, 'PAGE_TSCONFIG_') === 0) {
97 $this->pid = (int)$TSconfig[$this->P['field']][$keyword];
98 } else {
99 $this->pid = (int)$TSconfig['_' . $keyword];
100 }
101 } else {
102 $this->pid = (int)$this->P['params']['pid'];
103 }
104 // Make redirect:
105 // If pid is blank OR if id is set, then return...
106 if ((string)$this->id !== '') {
107 $redirectUrl = GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']);
108 } else {
109 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
110 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
111 // Otherwise, show the list:
112 $urlParameters = [];
113 $urlParameters['id'] = $this->pid;
114 $urlParameters['table'] = $this->P['params']['table'];
115 $urlParameters['returnUrl'] = !empty($this->P['returnUrl'])
116 ? GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])
117 : GeneralUtility::getIndpEnv('REQUEST_URI');
118 $redirectUrl = (string)$uriBuilder->buildUriFromRoute('web_list', $urlParameters);
119 }
120 HttpUtility::redirect($redirectUrl);
121 }
122 }