[CLEANUP] EXT:backend/Classes/Wizard/*.php
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / AddController.php
index f25c327..bea7334 100644 (file)
@@ -14,9 +14,13 @@ namespace TYPO3\CMS\Backend\Controller\Wizard;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Form\DataPreprocessor;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
+use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\HttpUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 
 /**
  * Script Class for adding new items to a group/select field. Performs proper redirection as needed.
@@ -94,11 +98,11 @@ class AddController extends AbstractWizardController {
                $this->P = GeneralUtility::_GP('P');
                $this->returnEditConf = GeneralUtility::_GP('returnEditConf');
                // Get this record
-               $origRow = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
+               $record = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
                // Set table:
                $this->table = $this->P['params']['table'];
                // Get TSconfig for it.
-               $TSconfig = BackendUtility::getTCEFORM_TSconfig($this->P['table'], is_array($origRow) ? $origRow : array('pid' => $this->P['pid']));
+               $TSconfig = BackendUtility::getTCEFORM_TSconfig($this->P['table'], is_array($record) ? $record : array('pid' => $this->P['pid']));
                // Set [params][pid]
                if (substr($this->P['params']['pid'], 0, 3) === '###' && substr($this->P['params']['pid'], -3) === '###') {
                        $keyword = substr($this->P['params']['pid'], 3, -3);
@@ -117,16 +121,17 @@ class AddController extends AbstractWizardController {
                // Else proceed:
                // If a new id has returned from a newly created record...
                if ($this->returnEditConf) {
-                       $eC = json_decode($this->returnEditConf, TRUE);
-                       if (is_array($eC[$this->table]) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->P['uid'])) {
+                       $editConfiguration = json_decode($this->returnEditConf, TRUE);
+                       if (is_array($editConfiguration[$this->table]) && MathUtility::canBeInterpretedAsInteger($this->P['uid'])) {
                                // Getting id and cmd from returning editConf array.
-                               reset($eC[$this->table]);
-                               $this->id = (int)key($eC[$this->table]);
-                               $cmd = current($eC[$this->table]);
+                               reset($editConfiguration[$this->table]);
+                               $this->id = (int)key($editConfiguration[$this->table]);
+                               $cmd = current($editConfiguration[$this->table]);
                                // ... and if everything seems OK we will register some classes for inclusion and instruct the object to perform processing later.
-                               if ($this->P['params']['setValue'] && $cmd == 'edit' && $this->id && $this->P['table'] && $this->P['field'] && $this->P['uid']) {
-                                       if ($LiveRec = BackendUtility::getLiveVersionOfRecord($this->table, $this->id, 'uid')) {
-                                               $this->id = $LiveRec['uid'];
+                               if ($this->P['params']['setValue'] && $cmd === 'edit' && $this->id && $this->P['table'] && $this->P['field'] && $this->P['uid']) {
+                                       $liveRecord = BackendUtility::getLiveVersionOfRecord($this->table, $this->id, 'uid');
+                                       if ($liveRecord) {
+                                               $this->id = $liveRecord['uid'];
                                        }
                                        $this->processDataFlag = 1;
                                }
@@ -144,55 +149,58 @@ class AddController extends AbstractWizardController {
                if ($this->returnEditConf) {
                        if ($this->processDataFlag) {
                                // Preparing the data of the parent record...:
-                               $trData = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\DataPreprocessor::class);
+                               /** @var DataPreprocessor $dataPreprocessor */
+                               $dataPreprocessor = GeneralUtility::makeInstance(DataPreprocessor::class);
                                // 'new'
-                               $trData->fetchRecord($this->P['table'], $this->P['uid'], '');
-                               $current = reset($trData->regTableItems_data);
-                               // If that record was found (should absolutely be...), then init TCEmain and set, prepend or append the record
+                               $dataPreprocessor->fetchRecord($this->P['table'], $this->P['uid'], '');
+                               $current = reset($dataPreprocessor->regTableItems_data);
+                               // If that record was found (should absolutely be...), then init DataHandler and set, prepend or append the record
                                if (is_array($current)) {
-                                       $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-                                       $tce->stripslashes_values = 0;
+                                       /** @var DataHandler $dataHandler */
+                                       $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
+                                       $dataHandler->stripslashes_values = FALSE;
                                        $data = array();
-                                       $addEl = $this->table . '_' . $this->id;
+                                       $recordId = $this->table . '_' . $this->id;
                                        // Setting the new field data:
-                                       // If the field is a flexform field, work with the XML structure instead:
+                                       // If the field is a flexForm field, work with the XML structure instead:
                                        if ($this->P['flexFormPath']) {
-                                               // Current value of flexform path:
+                                               // Current value of flexForm path:
                                                $currentFlexFormData = GeneralUtility::xml2array($current[$this->P['field']]);
-                                               $flexToolObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::class);
-                                               $curValueOfFlexform = $flexToolObj->getArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData);
+                                               /** @var FlexFormTools $flexFormTools */
+                                               $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
+                                               $currentFlexFormValue = $flexFormTools->getArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData);
                                                $insertValue = '';
                                                switch ((string)$this->P['params']['setValue']) {
                                                        case 'set':
-                                                               $insertValue = $addEl;
+                                                               $insertValue = $recordId;
                                                                break;
                                                        case 'prepend':
-                                                               $insertValue = $curValueOfFlexform . ',' . $addEl;
+                                                               $insertValue = $currentFlexFormValue . ',' . $recordId;
                                                                break;
                                                        case 'append':
-                                                               $insertValue = $addEl . ',' . $curValueOfFlexform;
+                                                               $insertValue = $recordId . ',' . $currentFlexFormValue;
                                                                break;
                                                }
                                                $insertValue = implode(',', GeneralUtility::trimExplode(',', $insertValue, TRUE));
                                                $data[$this->P['table']][$this->P['uid']][$this->P['field']] = array();
-                                               $flexToolObj->setArrayValueByPath($this->P['flexFormPath'], $data[$this->P['table']][$this->P['uid']][$this->P['field']], $insertValue);
+                                               $flexFormTools->setArrayValueByPath($this->P['flexFormPath'], $data[$this->P['table']][$this->P['uid']][$this->P['field']], $insertValue);
                                        } else {
                                                switch ((string)$this->P['params']['setValue']) {
                                                        case 'set':
-                                                               $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl;
+                                                               $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $recordId;
                                                                break;
                                                        case 'prepend':
-                                                               $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $current[$this->P['field']] . ',' . $addEl;
+                                                               $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $current[$this->P['field']] . ',' . $recordId;
                                                                break;
                                                        case 'append':
-                                                               $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl . ',' . $current[$this->P['field']];
+                                                               $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $recordId . ',' . $current[$this->P['field']];
                                                                break;
                                                }
                                                $data[$this->P['table']][$this->P['uid']][$this->P['field']] = implode(',', GeneralUtility::trimExplode(',', $data[$this->P['table']][$this->P['uid']][$this->P['field']], TRUE));
                                        }
                                        // Submit the data:
-                                       $tce->start($data, array());
-                                       $tce->process_datamap();
+                                       $dataHandler->start($data, array());
+                                       $dataHandler->process_datamap();
                                }
                        }
                        // Return to the parent FormEngine record editing session: