63a9a561d0503efff46b8cb4cf712da4f0ace720
[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 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_wizards.xlf');
60 $GLOBALS['SOBE'] = $this;
61 $this->P = GeneralUtility::_GP('P');
62 $this->table = GeneralUtility::_GP('table');
63 $this->id = GeneralUtility::_GP('id');
64 }
65
66 /**
67 * Injects the request object for the current request or subrequest
68 * As this controller goes only through the main() method, it is rather simple for now
69 *
70 * @param ServerRequestInterface $request
71 * @param ResponseInterface $response
72 * @return ResponseInterface
73 */
74 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
75 {
76 $this->main();
77 return $response;
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 // Otherwise, show the list:
110 $urlParameters = [];
111 $urlParameters['id'] = $this->pid;
112 $urlParameters['table'] = $this->P['params']['table'];
113 $urlParameters['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
114 $redirectUrl = BackendUtility::getModuleUrl('web_list', $urlParameters);
115 }
116 HttpUtility::redirect($redirectUrl);
117 }
118 }