[BUGFIX] Ignore unique evaluation in l10n_mode exclude 51/56151/9
authorChristoph Lehmann <christoph.lehmann@networkteam.com>
Wed, 14 Mar 2018 22:17:53 +0000 (23:17 +0100)
committerBenni Mack <benni@typo3.org>
Mon, 29 Oct 2018 16:11:09 +0000 (17:11 +0100)
The l10n_mode "exclude" explains to copy the field value from
source language, so unique evaluation should be ignored for
translated records.

Resolves: #84267
Resolves: #83572
Releases: master, 8.7
Change-Id: I6a086cb1fc447dda2cbcfe27f33ba9f3dd714f53
Reviewed-on: https://review.typo3.org/56151
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/GetUniqueTranslationTest.php

index 0f2e0f9..4f7d6a0 100644 (file)
@@ -2765,24 +2765,35 @@ class DataHandler implements LoggerAwareInterface
      */
     public function getUnique($table, $field, $value, $id, $newPid = 0)
     {
-        // If the field is configured in TCA, proceed:
-        if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
-            $newValue = $value;
-            $statement = $this->getUniqueCountStatement($newValue, $table, $field, (int)$id, (int)$newPid);
-            // For as long as records with the test-value existing, try again (with incremented numbers appended)
-            if ($statement->fetchColumn()) {
-                for ($counter = 0; $counter <= 100; $counter++) {
-                    $newValue = $value . $counter;
-                    $statement->bindValue(1, $newValue);
-                    $statement->execute();
-                    if (!$statement->fetchColumn()) {
-                        break;
-                    }
+        if (!is_array($GLOBALS['TCA'][$table]) || !is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
+            // Field is not configured in TCA
+            return $value;
+        }
+
+        if ((string)$GLOBALS['TCA'][$table]['columns'][$field]['l10n_mode'] === 'exclude') {
+            $transOrigPointerField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
+            $l10nParent = (int)$this->checkValue_currentRecord[$transOrigPointerField];
+            if ($l10nParent > 0) {
+                // Current record is a translation and l10n_mode "exclude" just copies the value from source language
+                return $value;
+            }
+        }
+
+        $newValue = $value;
+        $statement = $this->getUniqueCountStatement($newValue, $table, $field, (int)$id, (int)$newPid);
+        // For as long as records with the test-value existing, try again (with incremented numbers appended)
+        if ($statement->fetchColumn()) {
+            for ($counter = 0; $counter <= 100; $counter++) {
+                $newValue = $value . $counter;
+                $statement->bindValue(1, $newValue);
+                $statement->execute();
+                if (!$statement->fetchColumn()) {
+                    break;
                 }
             }
-            $value = $newValue;
         }
-        return $value;
+
+        return $newValue;
     }
 
     /**
index 85d3fde..ba48f46 100644 (file)
@@ -37,6 +37,6 @@ class GetUniqueTranslationTest extends AbstractDataHandlerActionTestCase
         $translatedRecord = BackendUtility::getRecord('pages', $newPageId);
 
         $this->assertEquals('datahandler', $originalLanguageRecord['alias']);
-        $this->assertEquals('datahandler0', $translatedRecord['alias']);
+        $this->assertEquals('datahandler', $translatedRecord['alias']);
     }
 }