TYPO3 CMS  TYPO3_7-6
EditController.php
Go to the documentation of this file.
1 <?php
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 
24 
29 {
35  public $P;
36 
42  public $doClose;
43 
49  protected $closeWindow = '<script language="javascript" type="text/javascript">close();</script>';
50 
54  public function __construct()
55  {
56  parent::__construct();
57  $this->getLanguageService()->includeLLFile('EXT:lang/locallang_wizards.xlf');
58  $GLOBALS['SOBE'] = $this;
59 
60  $this->init();
61  }
62 
68  protected function init()
69  {
70  $this->P = GeneralUtility::_GP('P');
71  // Used for the return URL to FormEngine so that we can close the window.
72  $this->doClose = GeneralUtility::_GP('doClose');
73  }
74 
83  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
84  {
85  $content = $this->main();
86  $response->getBody()->write($content);
87  return $response;
88  }
89 
97  public function main()
98  {
99  if ($this->doClose) {
100  return $this->closeWindow;
101  }
102  // Initialize:
103  $table = $this->P['table'];
104  $field = $this->P['field'];
105  $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
106  $fTable = $config['foreign_table'];
107 
108  $urlParameters = [
109  'returnUrl' => BackendUtility::getModuleUrl('wizard_edit', ['doClose' => 1])
110  ];
111 
112  // Detecting the various allowed field type setups and acting accordingly.
113  if (is_array($config)
114  && $config['type'] === 'select'
115  && !$config['MM']
116  && $config['maxitems'] <= 1 && MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
117  && $this->P['currentValue'] && $fTable
118  ) {
119  // SINGLE value
120  $urlParameters['edit[' . $fTable . '][' . $this->P['currentValue'] . ']'] = 'edit';
121  // Redirect to FormEngine
122  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
123  HttpUtility::redirect($url);
124  } elseif (is_array($config)
125  && $this->P['currentSelectedValues']
126  && ($config['type'] === 'select'
127  && $config['foreign_table']
128  || $config['type'] === 'group'
129  && $config['internal_type'] === 'db'
130  )
131  ) {
132  // MULTIPLE VALUES:
133  // Init settings:
134  $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table'];
135  $prependName = 1;
136  // Selecting selected values into an array:
138  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
139  $relationHandler->start($this->P['currentSelectedValues'], $allowedTables);
140  $value = $relationHandler->getValueArray($prependName);
141  // Traverse that array and make parameters for FormEngine
142  foreach ($value as $rec) {
143  $recTableUidParts = GeneralUtility::revExplode('_', $rec, 2);
144  $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit';
145  }
146  // Redirect to FormEngine
147  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
148  HttpUtility::redirect($url);
149  } else {
150  return $this->closeWindow;
151  }
152  }
153 
160  public function closeWindow()
161  {
163  echo $this->closeWindow;
164  die;
165  }
166 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76
static revExplode($delimiter, $string, $count=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']