[BUGFIX] Fatal Error in filelist when editing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataTraverser.php
index 21eeee7..07f173d 100644 (file)
@@ -168,7 +168,17 @@ class FormDataTraverser {
                                $possibleUids = $this->getRelatedGroupFieldUids($fieldConfig, $value);
                                break;
                        case 'select':
-                               $possibleUids = $this->getRelatedSelectFieldUids($fieldConfig, $fieldName, $value);
+                               /**
+                                * @var $selectObject \TYPO3\CMS\Backend\Form\Element\SelectElement
+                                */
+                               $selectObject = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\SelectElement::class, $this->formEngine);
+                               $selectObject->setCurrentRow($this->currentRow);
+                               $selectObject->setCurrentTable($this->currentTable);
+                               $selectObject->setAlternativeFieldValue($this->alternativeFieldValue);
+                               $selectObject->setForceAlternativeFieldValueUse($this->forceAlternativeFieldValueUse);
+                               $possibleUids = $selectObject->getRelatedSelectFieldUids($fieldConfig, $fieldName, $value);
+                               $this->alternativeFieldValue = $selectObject->getAlternativeFieldValue();
+                               $this->forceAlternativeFieldValueUse = $selectObject->isForceAlternativeFieldValueUse();
                                break;
                        case 'inline':
                                $possibleUids = $this->getRelatedInlineFieldUids($fieldConfig, $fieldName, $value);
@@ -221,81 +231,6 @@ class FormDataTraverser {
                return $relatedUids;
        }
 
-       /**
-        * If the select field is build by a foreign_table the related UIDs
-        * will be returned.
-        *
-        * Otherwise the label of the currently selected value will be written
-        * to the alternativeFieldValue class property.
-        *
-        * @param array $fieldConfig The "config" section of the TCA for the current select field.
-        * @param string $fieldName The name of the select field.
-        * @param string $value The current value in the local record, usually a comma separated list of selected values.
-        * @return array Array of related UIDs.
-        */
-       protected function getRelatedSelectFieldUids(array $fieldConfig, $fieldName, $value) {
-               $relatedUids = array();
-
-               $isTraversable = FALSE;
-               if (isset($fieldConfig['foreign_table'])) {
-                       $isTraversable = TRUE;
-                       // if a foreign_table is used we pre-filter the records for performance
-                       $fieldConfig['foreign_table_where'] .= ' AND ' . $fieldConfig['foreign_table'] . '.uid IN (' . $value . ')';
-               }
-
-               $PA = array();
-               $PA['fieldConf']['config'] = $fieldConfig;
-               $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type'];
-               $PA['fieldTSConfig'] = $this->formEngine->setTSconfig($this->currentTable, $this->currentRow, $fieldName);
-               $PA['fieldConf']['config'] = $this->formEngine->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
-               $selectItemArray = $this->formEngine->getSelectItems($this->currentTable, $fieldName, $this->currentRow, $PA);
-
-               if ($isTraversable && count($selectItemArray)) {
-                       $this->currentTable = $fieldConfig['foreign_table'];
-                       $relatedUids = $this->getSelectedValuesFromSelectItemArray($selectItemArray, $value);
-               } else {
-                       $selectedLabels = $this->getSelectedValuesFromSelectItemArray($selectItemArray, $value, 1, TRUE);
-                       if (count($selectedLabels) === 1) {
-                               $this->alternativeFieldValue = $selectedLabels[0];
-                               $this->forceAlternativeFieldValueUse = TRUE;
-                       }
-               }
-
-               return $relatedUids;
-       }
-
-       /**
-        * Extracts the selected values from a given array of select items.
-        *
-        * @param array $selectItemArray The select item array generated by \TYPO3\CMS\Backend\Form\FormEngine->getSelectItems.
-        * @param string $value The currently selected value(s) as comma separated list.
-        * @param int|NULL $maxItems Optional value, if set processing is skipped and an empty array will be returned when the number of selected values is larger than the provided value.
-        * @param bool $returnLabels If TRUE the select labels will be returned instead of the values.
-        * @return array
-        */
-       protected function getSelectedValuesFromSelectItemArray(array $selectItemArray, $value, $maxItems = NULL, $returnLabels = FALSE) {
-               $values = GeneralUtility::trimExplode(',', $value);
-               $selectedValues = array();
-
-               if ($maxItems !== NULL && (count($values) > (int)$maxItems)) {
-                       return $selectedValues;
-               }
-
-               foreach ($selectItemArray as $selectItem) {
-                       $selectItemValue = $selectItem[1];
-                       if (in_array($selectItemValue, $values)) {
-                               if ($returnLabels) {
-                                       $selectedValues[] = $selectItem[0];
-                               } else {
-                                       $selectedValues[] = $selectItemValue;
-                               }
-                       }
-               }
-
-               return $selectedValues;
-       }
-
-
        /**
         * Tries to get the related UID of an inline field.
         *