[BUGFIX] Use given redirectUrl in „list“ wizard, if available
[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\Utility\GeneralUtility;
21 use TYPO3\CMS\Core\Utility\HttpUtility;
22
23 /**
24 * Script Class for redirecting the user to the Web > List module if a wizard-link has been clicked in FormEngine
25 */
26 class ListController extends AbstractWizardController
27 {
28 /**
29 * @var int
30 */
31 public $pid;
32
33 /**
34 * Wizard parameters, coming from FormEngine linking to the wizard.
35 *
36 * @var array
37 */
38 public $P;
39
40 /**
41 * Table to show, if none, then all tables are listed in list module.
42 *
43 * @var string
44 */
45 public $table;
46
47 /**
48 * Page id to list.
49 *
50 * @var string
51 */
52 public $id;
53
54 /**
55 * Initialization of the class, setting GPvars.
56 */
57 public function __construct()
58 {
59 parent::__construct();
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 * @param ResponseInterface $response
73 * @return ResponseInterface
74 */
75 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
76 {
77 $this->main();
78 return $response;
79 }
80
81 /**
82 * Main function
83 * Will issue a location-header, redirecting either BACK or to a new FormEngine instance...
84 */
85 public function main()
86 {
87 // Get this record
88 $origRow = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
89 // Get TSconfig for it.
90 $TSconfig = BackendUtility::getTCEFORM_TSconfig(
91 $this->table,
92 is_array($origRow) ? $origRow : ['pid' => $this->P['pid']]
93 );
94 // Set [params][pid]
95 if (substr($this->P['params']['pid'], 0, 3) === '###' && substr($this->P['params']['pid'], -3) === '###') {
96 $keyword = substr($this->P['params']['pid'], 3, -3);
97 if (strpos($keyword, 'PAGE_TSCONFIG_') === 0) {
98 $this->pid = (int)$TSconfig[$this->P['field']][$keyword];
99 } else {
100 $this->pid = (int)$TSconfig['_' . $keyword];
101 }
102 } else {
103 $this->pid = (int)$this->P['params']['pid'];
104 }
105 // Make redirect:
106 // If pid is blank OR if id is set, then return...
107 if ((string)$this->id !== '') {
108 $redirectUrl = GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']);
109 } else {
110 // Otherwise, show the list:
111 $urlParameters = [];
112 $urlParameters['id'] = $this->pid;
113 $urlParameters['table'] = $this->P['params']['table'];
114 $urlParameters['returnUrl'] = !empty($this->P['returnUrl'])
115 ? GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])
116 : GeneralUtility::getIndpEnv('REQUEST_URI');
117 $redirectUrl = BackendUtility::getModuleUrl('web_list', $urlParameters);
118 }
119 HttpUtility::redirect($redirectUrl);
120 }
121 }