[BUGFIX] Show language diffs below FormEngine fields 80/43380/3
authorGeorg Ringer <georg.ringer@gmail.com>
Wed, 16 Sep 2015 18:35:01 +0000 (20:35 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 17 Sep 2015 16:32:19 +0000 (18:32 +0200)
Fix display of language diffs below fields of FormEngine.

Change-Id: Ie41995ffc38413a060e456ffda1712ed7722c2df
Resolves: #69896
Releases: master
Reviewed-on: http://review.typo3.org/43380
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseLanguageRows.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseLanguageRowsTest.php

index 88bbb10..d80ab84 100644 (file)
@@ -318,15 +318,15 @@ class SingleFieldContainer extends AbstractContainer {
         * @return string Item string returned again, possibly with the original value added to.
         */
        protected function renderDefaultLanguageContent($table, $field, $row, $item) {
-               if (is_array($this->data['defaultLanguageData'][$table . ':' . $row['uid']])) {
+               if (is_array($this->data['defaultLanguageRow'])) {
                        $defaultLanguageValue = BackendUtility::getProcessedValue(
                                $table,
                                $field,
-                               $this->data['defaultLanguageData'][$table . ':' . $row['uid']][$field],
+                               $this->data['defaultLanguageRow'][$field],
                                0,
                                1,
                                FALSE,
-                               $this->data['defaultLanguageData'][$table . ':' . $row['uid']]['uid']
+                               $this->data['defaultLanguageRow']['uid']
                        );
                        $fieldConfig = $this->data['processedTca']['columns'][$field];
                        // Don't show content if it's for IRRE child records:
@@ -337,18 +337,18 @@ class SingleFieldContainer extends AbstractContainer {
                                                . $this->getMergeBehaviourIcon($fieldConfig['l10n_mode'])
                                                . $this->previewFieldValue($defaultLanguageValue, $fieldConfig, $field) . '</div>';
                                }
-                               $additionalPreviewLanguages = $this->data['additionalPreviewLanguages'];
+                               $additionalPreviewLanguages = $this->data['additionalLanguageRows'];
                                foreach ($additionalPreviewLanguages as $previewLanguage) {
                                        $defaultLanguageValue = BackendUtility::getProcessedValue(
                                                $table,
                                                $field,
-                                               $this->data['additionalPreviewLanguageData'][$table . ':' . $row['uid']][$previewLanguage['uid']][$field],
+                                               $previewLanguage[$field],
                                                0,
-                                               1
+                                               TRUE
                                        );
                                        if ($defaultLanguageValue !== '') {
                                                $item .= '<div class="t3-form-original-language" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_misc.xlf:localizeMergeIfNotBlank', TRUE) . '">'
-                                                       . FormEngineUtility::getLanguageIcon($table, $row, ('v' . $previewLanguage['ISOcode']))
+                                                       . FormEngineUtility::getLanguageIcon($table, $row, $previewLanguage['sys_language_uid'])
                                                        . $this->getMergeBehaviourIcon($fieldConfig['l10n_mode'])
                                                        . $this->previewFieldValue($defaultLanguageValue, $fieldConfig, $field) . '</div>';
                                        }
index 15f52c4..fb13beb 100644 (file)
@@ -79,8 +79,11 @@ class DatabaseLanguageRows implements FormDataProviderInterface {
                                        /** @var TranslationConfigurationProvider $translationProvider */
                                        $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
                                        foreach ($additionalLanguageUids as $additionalLanguageUid) {
-                                               // Continue if this system language record does not exist or if 0 is requested
-                                               if ($additionalLanguageUid === 0 || !isset($result['systemLanguageRows'][$additionalLanguageUid])) {
+                                               // Continue if this system language record does not exist or if 0 is requested or if row is the same as the to-be-displayed row
+                                               if ($additionalLanguageUid === 0
+                                                       || !isset($result['systemLanguageRows'][$additionalLanguageUid])
+                                                       || $additionalLanguageUid === (int)$result['databaseRow'][$languageField]
+                                               ) {
                                                        continue;
                                                }
                                                $translationInfo = $translationProvider->translationInfo(
index 2d90c69..156763b 100644 (file)
@@ -119,7 +119,7 @@ class DatabaseLanguageRowsTest extends UnitTestCase {
                ];
                // Needed for BackendUtility::getRecord
                $GLOBALS['TCA']['tt_content'] = array('foo');
-               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->willReturn($defaultLanguageRow);
+               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
 
                $expected = $input;
                $expected['defaultLanguageRow'] = $defaultLanguageRow;
@@ -162,7 +162,7 @@ class DatabaseLanguageRowsTest extends UnitTestCase {
                ];
                // Needed for BackendUtility::getRecord
                $GLOBALS['TCA']['tt_content'] = array('foo');
-               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->willReturn($defaultLanguageRow);
+               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
 
                $expected = $input;
                $expected['defaultLanguageRow'] = $defaultLanguageRow;
@@ -231,7 +231,7 @@ class DatabaseLanguageRowsTest extends UnitTestCase {
                ];
                // Needed for BackendUtility::getRecord
                $GLOBALS['TCA']['tt_content'] = array('foo');
-               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->willReturn($defaultLanguageRow);
+               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
 
                /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
                $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
@@ -253,4 +253,92 @@ class DatabaseLanguageRowsTest extends UnitTestCase {
                $this->assertEquals($expected, $this->subject->addData($input));
        }
 
+       /**
+        * @test
+        */
+       public function addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows() {
+               $input = [
+                       'tableName' => 'tt_content',
+                       'databaseRow' => [
+                               'uid' => 42,
+                               'text' => 'localized text',
+                               'sys_language_uid' => 2,
+                               'l10n_parent' => 23,
+                       ],
+                       'vanillaTableTca' => [
+                               'ctrl' => [
+                                       'languageField' => 'sys_language_uid',
+                                       'transOrigPointerField' => 'l10n_parent',
+                               ],
+                       ],
+                       'userTsConfig' => [
+                               'options.' => [
+                                       'additionalPreviewLanguages' => '2,3',
+                               ],
+                       ],
+                       'systemLanguageRows' => [
+                               0 => [
+                                       'uid' => 0,
+                                       'title' => 'Default Language',
+                                       'iso' => 'DEV',
+                               ],
+                               2 => [
+                                       'uid' => 2,
+                                       'title' => 'dansk',
+                                       'iso' => 'dk,'
+                               ],
+                               3 => [
+                                       'uid' => 3,
+                                       'title' => 'french',
+                                       'iso' => 'fr',
+                               ],
+                       ],
+                       'defaultLanguageRow' => NULL,
+                       'additionalLanguageRows' => [],
+               ];
+
+               $translationResult = [
+                       'translations' => [
+                               3 => [
+                                       'uid' => 43,
+                               ],
+                       ],
+               ];
+               // For BackendUtility::getRecord()
+               $GLOBALS['TCA']['tt_content'] = array('foo');
+               $recordWsolResult = [
+                       'uid' => 43,
+                       'text' => 'localized text in french',
+               ];
+
+               $defaultLanguageRow = [
+                       'uid' => 23,
+                       'text' => 'default language text',
+                       'sys_language_uid' => 0,
+               ];
+               // Needed for BackendUtility::getRecord
+               $GLOBALS['TCA']['tt_content'] = array('foo');
+               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
+
+               /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
+               $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
+               GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
+               $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
+               $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
+
+               // This is the real check: The "additional overlay" should be fetched
+               $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
+
+               $expected = $input;
+               $expected['defaultLanguageRow'] = $defaultLanguageRow;
+               $expected['additionalLanguageRows'] = [
+                       3 => [
+                               'uid' => 43,
+                               'text' => 'localized text in french',
+                       ],
+               ];
+
+               $this->assertEquals($expected, $this->subject->addData($input));
+       }
+
 }