TYPO3 CMS  TYPO3_8-7
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 
25 
30 {
36  public $P;
37 
43  public $doClose;
44 
50  protected $closeWindow = '<script language="javascript" type="text/javascript">close();</script>';
51 
55  public function __construct()
56  {
57  parent::__construct();
58  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_wizards.xlf');
59  $GLOBALS['SOBE'] = $this;
60 
61  $this->init();
62  }
63 
67  protected function init()
68  {
69  $this->P = GeneralUtility::_GP('P');
70  // Used for the return URL to FormEngine so that we can close the window.
71  $this->doClose = GeneralUtility::_GP('doClose');
72  }
73 
82  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
83  {
84  $content = $this->main();
85  $response->getBody()->write($content);
86  return $response;
87  }
88 
96  public function main()
97  {
98  if ($this->doClose) {
99  return $this->closeWindow;
100  }
101  // Initialize:
102  $table = $this->P['table'];
103  $field = $this->P['field'];
104 
105  if (empty($this->P['flexFormDataStructureIdentifier'])) {
106  // If there is not flex data structure identifier, field config is found in globals
107  $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
108  } else {
109  // If there is a flex data structure identifier, parse that data structure and
110  // fetch config defined by given flex path
111  $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
112  $dataStructure = $flexFormTools->parseDataStructureByIdentifier($this->P['flexFormDataStructureIdentifier']);
113  $config = $flexFormTools->getArrayValueByPath($this->P['flexFormDataStructurePath'], $dataStructure);
114  if (!is_array($config)) {
115  throw new \RuntimeException(
116  'Something went wrong finding flex path ' . $this->P['flexFormDataStructurePath']
117  . ' in data structure identified by ' . $this->P['flexFormDataStructureIdentifier'],
118  1537356346
119  );
120  }
121  }
122 
123  $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
124  $urlParameters = [
125  'returnUrl' => BackendUtility::getModuleUrl('wizard_edit', ['doClose' => 1])
126  ];
127 
128  // Detecting the various allowed field type setups and acting accordingly.
129  if (is_array($config)
130  && $config['type'] === 'select'
131  && !$config['MM']
132  && $config['maxitems'] <= 1
133  && MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
134  && $this->P['currentValue']
135  && $config['foreign_table']
136  ) {
137  // SINGLE value
138  $urlParameters['edit[' . $config['foreign_table'] . '][' . $this->P['currentValue'] . ']'] = 'edit';
139  // Redirect to FormEngine
140  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
141  HttpUtility::redirect($url);
142  } elseif (is_array($config)
143  && $this->P['currentSelectedValues']
144  && (
145  $config['type'] === 'select'
146  && $config['foreign_table']
147  || $config['type'] === 'group'
148  && $config['internal_type'] === 'db'
149  )
150  ) {
151  // MULTIPLE VALUES:
152  // Init settings:
153  $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table'];
154  $prependName = 1;
155  // Selecting selected values into an array:
157  $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
158  $relationHandler->start($this->P['currentSelectedValues'], $allowedTables);
159  $value = $relationHandler->getValueArray($prependName);
160  // Traverse that array and make parameters for FormEngine
161  foreach ($value as $rec) {
162  $recTableUidParts = GeneralUtility::revExplode('_', $rec, 2);
163  $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit';
164  }
165  // Redirect to FormEngine
166  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
167  HttpUtility::redirect($url);
168  } else {
169  return $this->closeWindow;
170  }
171  }
172 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static makeInstance($className,... $constructorArguments)
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
static revExplode($delimiter, $string, $count=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']