[BUGFIX] Handle l10n_parent if field is no select-type 77/49477/2
authorMarkus Klein <markus.klein@typo3.org>
Fri, 29 Jul 2016 09:31:39 +0000 (11:31 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 14 Aug 2016 13:08:26 +0000 (15:08 +0200)
The value of l10n_parent is not necessarily an array.
It may as well be a string from a group-type or simple
input.
Adjust the condition for overlay detection accordingly.

Resolves: #77301
Releases: master, 7.6
Change-Id: I9119dfc0a55d623f037f15ddf1e11f132cf38c0b
Reviewed-on: https://review.typo3.org/49477
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php

index b13ae82..37d0298 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
 use TYPO3\CMS\Core\Utility\DiffUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Lang\LanguageService;
 
 /**
@@ -65,10 +66,25 @@ class SingleFieldContainer extends AbstractContainer
         // Based on this decision we need to trigger field exclusion or special rendering (like readOnly)
         if (isset($this->data['processedTca']['ctrl']['transOrigPointerField'])
             && is_array($this->data['processedTca']['columns'][$this->data['processedTca']['ctrl']['transOrigPointerField']])
-            && is_array($row[$this->data['processedTca']['ctrl']['transOrigPointerField']])
-            && $row[$this->data['processedTca']['ctrl']['transOrigPointerField']][0] > 0
         ) {
-            $isOverlay = true;
+            $parentValue = $row[$this->data['processedTca']['ctrl']['transOrigPointerField']];
+            if (MathUtility::canBeInterpretedAsInteger($parentValue)) {
+                $isOverlay = (bool)$parentValue;
+            } elseif (is_array($parentValue)) {
+                // This case may apply if the value has been converted to an array by the select data provider
+                $isOverlay = !empty($parentValue) ? (bool)$parentValue[0] : false;
+            } elseif (is_string($parentValue) && $parentValue !== '') {
+                // This case may apply if a group definition is used in TCA and the group provider builds a weird string
+                $recordsReferencedInField = GeneralUtility::trimExplode(',', $parentValue);
+                // Pick the first record because if you set multiple records you're in trouble anyways
+                $recordIdentifierParts = GeneralUtility::trimExplode('|', $recordsReferencedInField[0]);
+                list(, $refUid) = BackendUtility::splitTable_Uid($recordIdentifierParts[0]);
+                $isOverlay = MathUtility::canBeInterpretedAsInteger($refUid) ? (bool)$refUid : false;
+            } else {
+                throw new \InvalidArgumentException('The given value for the original language field '
+                                                    . $this->data['processedTca']['ctrl']['transOrigPointerField']
+                                                    . ' of table ' . $table . ' contains an invalid value.', 1470742770);
+            }
         }
 
         // A couple of early returns in case the field should not be rendered
@@ -79,7 +95,7 @@ class SingleFieldContainer extends AbstractContainer
             // @todo: Drop option "showIfRTE" ?
             || !$backendUser->isRTE() && $parameterArray['fieldConf']['config']['showIfRTE']
             // Return if field should not be rendered in translated records
-            || $isOverlay && !$parameterArray['fieldConf']['l10n_display'] && $parameterArray['fieldConf']['l10n_mode'] === 'exclude'
+            || $isOverlay && empty($parameterArray['fieldConf']['l10n_display']) && $parameterArray['fieldConf']['l10n_mode'] === 'exclude'
             // @todo: localizationMode still needs handling!
             || $isOverlay && $this->data['localizationMode'] && $this->data['localizationMode'] !== $parameterArray['fieldConf']['l10n_cat']
             || $this->inlineFieldShouldBeSkipped()