[BUGFIX] Fatal Error in filelist when editing 85/35385/2
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sat, 13 Dec 2014 12:50:04 +0000 (13:50 +0100)
committerBenjamin Mack <benni@typo3.org>
Sun, 14 Dec 2014 10:12:56 +0000 (11:12 +0100)
Regression fix for #61958

Fixes: #63825
Releases: master
Relates: #61958
Change-Id: I06818243c296ac20b5b5f251e5ab57c6a6008632
Reviewed-on: http://review.typo3.org/35385
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/Element/SelectElement.php
typo3/sysext/backend/Classes/Form/FormDataTraverser.php

index 07ffe3e..eccc9fe 100644 (file)
@@ -26,6 +26,36 @@ use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 class SelectElement extends AbstractFormElement {
 
        /**
+        * If this value is set during traversal and the traversal chain can
+        * not be walked to the end this value will be returned instead.
+        *
+        * @var string
+        */
+       protected $alternativeFieldValue;
+
+       /**
+        * If this is TRUE the alternative field value will be used even if
+        * the detected field value is not empty.
+        *
+        * @var bool
+        */
+       protected $forceAlternativeFieldValueUse = FALSE;
+
+       /**
+        * The row data of the record that is currently traversed.
+        *
+        * @var array
+        */
+       protected $currentRow;
+
+       /**
+        * Name of the table that is currently traversed.
+        *
+        * @var string
+        */
+       protected $currentTable;
+
+       /**
         * This will render a selector box element, or possibly a special construction with two selector boxes.
         * That depends on configuration.
         *
@@ -747,4 +777,138 @@ class SelectElement extends AbstractFormElement {
                                ';
                return $item;
        }
+
+       /**
+        * 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.
+        */
+       public 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->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;
+       }
+
+       /**
+        * @param string $alternativeFieldValue
+        */
+       public function setAlternativeFieldValue($alternativeFieldValue) {
+               $this->alternativeFieldValue = $alternativeFieldValue;
+       }
+
+       /**
+        * @param array $currentRow
+        */
+       public function setCurrentRow($currentRow) {
+               $this->currentRow = $currentRow;
+       }
+
+       /**
+        * @param string $currentTable
+        */
+       public function setCurrentTable($currentTable) {
+               $this->currentTable = $currentTable;
+       }
+
+       /**
+        * @param boolean $forceAlternativeFieldValueUse
+        */
+       public function setForceAlternativeFieldValueUse($forceAlternativeFieldValueUse) {
+               $this->forceAlternativeFieldValueUse = $forceAlternativeFieldValueUse;
+       }
+
+       /**
+        * @return string
+        */
+       public function getAlternativeFieldValue() {
+               return $this->alternativeFieldValue;
+       }
+
+       /**
+        * @return array
+        */
+       public function getCurrentRow() {
+               return $this->currentRow;
+       }
+
+       /**
+        * @return string
+        */
+       public function getCurrentTable() {
+               return $this->currentTable;
+       }
+
+       /**
+        * @return boolean
+        */
+       public function isForceAlternativeFieldValueUse() {
+               return $this->forceAlternativeFieldValueUse;
+       }
+
+
+
+
 }
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);
@@ -222,81 +232,6 @@ class FormDataTraverser {
        }
 
        /**
-        * 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.
         *
         * @param array $fieldConfig "config" section of the TCA configuration of the related inline field.