[CLEANUP] EXT:backend/Classes/Wizard/*.php
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / EditController.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 TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Database\RelationHandler;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Core\Utility\HttpUtility;
21
22 /**
23 * Script Class for redirecting a backend user to the editing form when an "Edit wizard" link was clicked in FormEngine somewhere
24 *
25 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
26 */
27 class EditController extends AbstractWizardController {
28
29 /**
30 * Wizard parameters, coming from FormEngine linking to the wizard.
31 *
32 * @var array
33 */
34 public $P;
35
36 /**
37 * Boolean; if set, the window will be closed by JavaScript
38 *
39 * @var int
40 */
41 public $doClose;
42
43 /**
44 * Constructor
45 */
46 public function __construct() {
47 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_wizards.xlf');
48 $GLOBALS['SOBE'] = $this;
49
50 $this->init();
51 }
52
53 /**
54 * Initialization of the script
55 *
56 * @return void
57 */
58 protected function init() {
59 $this->P = GeneralUtility::_GP('P');
60 // Used for the return URL to FormEngine so that we can close the window.
61 $this->doClose = GeneralUtility::_GP('doClose');
62 }
63
64 /**
65 * Main function
66 * Makes a header-location redirect to an edit form IF POSSIBLE from the passed data - otherwise the window will just close.
67 *
68 * @return void
69 */
70 public function main() {
71 if ($this->doClose) {
72 $this->closeWindow();
73 }
74 // Initialize:
75 $table = $this->P['table'];
76 $field = $this->P['field'];
77 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
78 $fTable = $this->P['currentValue'] < 0 ? $config['neg_foreign_table'] : $config['foreign_table'];
79
80 $urlParameters = array(
81 'returnUrl' => rawurlencode(BackendUtility::getModuleUrl('wizard_edit', array('doClose' => 1)))
82 );
83
84 // Detecting the various allowed field type setups and acting accordingly.
85 if (is_array($config) && $config['type'] === 'select' && !$config['MM'] && $config['maxitems'] <= 1 && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->P['currentValue']) && $this->P['currentValue'] && $fTable) {
86 // SINGLE value
87 $urlParameters['edit[' . $fTable . '][' . $this->P['currentValue'] . ']'] = 'edit';
88 // Redirect to FormEngine
89 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
90 HttpUtility::redirect($url);
91 } elseif (is_array($config) && $this->P['currentSelectedValues'] && ($config['type'] === 'select' && $config['foreign_table'] || $config['type'] === 'group' && $config['internal_type'] === 'db')) {
92 // MULTIPLE VALUES:
93 // Init settings:
94 $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table'] . ',' . $config['neg_foreign_table'];
95 $prependName = 1;
96 // Selecting selected values into an array:
97 /** @var RelationHandler $relationHandler */
98 $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
99 $relationHandler->start($this->P['currentSelectedValues'], $allowedTables);
100 $value = $relationHandler->getValueArray($prependName);
101 // Traverse that array and make parameters for FormEngine
102 foreach ($value as $rec) {
103 $recTableUidParts = GeneralUtility::revExplode('_', $rec, 2);
104 $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit';
105 }
106 // Redirect to FormEngine
107 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
108 HttpUtility::redirect($url);
109 } else {
110 $this->closeWindow();
111 }
112 }
113
114 /**
115 * Printing a little JavaScript to close the open window.
116 *
117 * @return void
118 */
119 public function closeWindow() {
120 echo '<script language="javascript" type="text/javascript">close();</script>';
121 die;
122 }
123
124 }