[BUGFIX] Make translating inline elements possible 38/44338/9
authorSebastian Fischer <typo3@evoweb.de>
Wed, 28 Oct 2015 18:00:18 +0000 (19:00 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 29 Oct 2015 14:46:26 +0000 (15:46 +0100)
If a translated parent record has inline childs its
now possible to translate new childs of the translation
parent of parent record.

For example if a tt_content element has new images
added to the default language its now possible to add
the translation for the image reference in the
translated content element.

Resolves: #70880
Releases: master
Change-Id: I6c19aaa9238232d0076509ce92fe84552fd69c18
Reviewed-on: https://review.typo3.org/44338
Reviewed-by: Benjamin Kott <info@bk2k.info>
Tested-by: Benjamin Kott <info@bk2k.info>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaInline.php

index 60cf8ae..f33c4b1 100644 (file)
@@ -344,8 +344,9 @@ class FormInlineAjaxController
                 // Do not compile existing children, we don't need them now
                 'inlineCompileExistingChildren' => false,
             ];
+            // Full TcaDatabaseRecord is required here to have the list of connected uids $oldItemList
             /** @var TcaDatabaseRecord $formDataGroup */
-            $formDataGroup = GeneralUtility::makeInstance(InlineParentRecord::class);
+            $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
             /** @var FormDataCompiler $formDataCompiler */
             $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
             $parentData = $formDataCompiler->compile($formDataCompilerInputForParent);
@@ -402,7 +403,7 @@ class FormInlineAjaxController
                 }
                 $jsonArray['scriptCall'][] = 'inline.memorizeAddRecord(' . GeneralUtility::quoteJSvalue($nameObjectForeignTable) . ', ' . GeneralUtility::quoteJSvalue($childUid) . ', null, ' . $selectedValue . ');';
                 // Remove possible virtual records in the form which showed that a child records could be localized:
-                $transOrigPointerFieldName = $GLOBALS['TCA'][$childData['table']]['ctrl']['transOrigPointerField'];
+                $transOrigPointerFieldName = $childData['processedTca']['ctrl']['transOrigPointerField'];
                 if (isset($childData['databaseRow'][$transOrigPointerFieldName]) && $childData['databaseRow'][$transOrigPointerFieldName]) {
                     $transOrigPointerField = $childData['databaseRow'][$transOrigPointerFieldName];
                     if (is_array($transOrigPointerField)) {
@@ -410,9 +411,16 @@ class FormInlineAjaxController
                     }
                     $jsonArray['scriptCall'][] = 'inline.fadeAndRemove(' . GeneralUtility::quoteJSvalue($nameObjectForeignTable . '-' . $transOrigPointerField . '_div') . ');';
                 }
-                if (!empty($childResult['html'])) {
-                    array_unshift($jsonArray['scriptCall'], 'inline.domAddNewRecord(\'bottom\', ' . GeneralUtility::quoteJSvalue($nameObject . '_records') . ', ' . GeneralUtility::quoteJSvalue($nameObjectForeignTable) . ', json.data);');
-                }
+
+            }
+            // Tell JS to add new HTML of one or multiple (localize all) records to DOM
+            if (!empty($jsonArray['data'])) {
+                array_push(
+                    $jsonArray['scriptCall'],
+                    'inline.domAddNewRecord(\'bottom\', ' . GeneralUtility::quoteJSvalue($nameObject . '_records')
+                    . ', ' . GeneralUtility::quoteJSvalue($nameObjectForeignTable)
+                    . ', json.data);'
+                );
             }
         }
 
@@ -536,7 +544,7 @@ class FormInlineAjaxController
      */
     protected function mergeChildResultIntoJsonResult(array $jsonResult, array $childResult)
     {
-        $jsonResult['data'] = $childResult['html'];
+        $jsonResult['data'] .= $childResult['html'];
         $jsonResult['stylesheetFiles'] = $childResult['stylesheetFiles'];
         if (!empty($childResult['inlineData'])) {
             $jsonResult['scriptCall'][] = 'inline.addToDataArray(' . json_encode($childResult['inlineData']) . ');';
index a77397f..7d5cac9 100644 (file)
@@ -161,35 +161,37 @@ class TcaInline extends AbstractDatabaseRecordProvider implements FormDataProvid
                     $result['defaultLanguageRow']['uid'],
                     $result['defaultLanguageRow'][$fieldName]
                 );
+
                 $showPossible = $result['processedTca']['columns'][$fieldName]['config']['appearance']['showPossibleLocalizationRecords'];
                 $showRemoved = $result['processedTca']['columns'][$fieldName]['config']['appearance']['showRemovedLocalizationRecords'];
-                if ($showPossible || $showRemoved) {
-                    // Find which records are localized, which records are not localized and which are
-                    // localized but miss default language record
-                    $fieldNameWithDefaultLanguageUid = $GLOBALS['TCA'][$childTableName]['ctrl']['transOrigPointerField'];
-                    foreach ($connectedUidsOfLocalizedOverlay as $localizedUid) {
-                        $localizedRecord = $this->getRecordFromDatabase($childTableName, $localizedUid);
-                        $uidOfDefaultLanguageRecord = $localizedRecord[$fieldNameWithDefaultLanguageUid];
-                        if (in_array($uidOfDefaultLanguageRecord, $connectedUidsOfDefaultLanguageRecord, true)) {
-                            // This localized child has a default language record. Remove this record from list of default language records
-                            $connectedUidsOfDefaultLanguageRecord = array_diff($connectedUidsOfDefaultLanguageRecord, array($uidOfDefaultLanguageRecord));
-                            // Compile localized record
-                            $result['processedTca']['columns'][$fieldName]['children'][] = $this->compileChild($result, $fieldName, $localizedUid);
-                        } elseif ($showRemoved) {
-                            // This localized child has no default language record. Compile child and mark it as such
-                            $compiledChild = $this->compileChild($result, $fieldName, $localizedUid);
-                            $compiledChild['inlineIsDanglingLocalization'] = true;
-                            $result['processedTca']['columns'][$fieldName]['children'][] = $compiledChild;
-                        } // Discard child if default language is missing and no showRemoved is set
-                    }
-                    if ($showPossible) {
-                        foreach ($connectedUidsOfDefaultLanguageRecord as $defaultLanguageUid) {
-                            // If there are still uids in $connectedUidsOfDefaultLanguageRecord, these are records that
-                            // exist in default language, but are not localized yet. Compile and mark those
-                            $compiledChild = $this->compileChild($result, $fieldName, $defaultLanguageUid);
-                            $compiledChild['inlineIsDefaultLanguage'] = true;
-                            $result['processedTca']['columns'][$fieldName]['children'][] = $compiledChild;
-                        }
+
+                // Find which records are localized, which records are not localized and which are
+                // localized but miss default language record
+                $fieldNameWithDefaultLanguageUid = $GLOBALS['TCA'][$childTableName]['ctrl']['transOrigPointerField'];
+                foreach ($connectedUidsOfLocalizedOverlay as $localizedUid) {
+                    $localizedRecord = $this->getRecordFromDatabase($childTableName, $localizedUid);
+                    $uidOfDefaultLanguageRecord = $localizedRecord[$fieldNameWithDefaultLanguageUid];
+                    if (in_array($uidOfDefaultLanguageRecord, $connectedUidsOfDefaultLanguageRecord)) {
+                        // This localized child has a default language record. Remove this record from list of default language records
+                        $connectedUidsOfDefaultLanguageRecord = array_diff($connectedUidsOfDefaultLanguageRecord, array($uidOfDefaultLanguageRecord));
+                        // Compile localized record
+                        $compiledChild = $this->compileChild($result, $fieldName, $localizedUid);
+                        $compiledChild['inlineIsTranslationWithDefaultLanguage'] = true;
+                        $result['processedTca']['columns'][$fieldName]['children'][] = $compiledChild;
+                    } elseif ($showRemoved) {
+                        // This localized child has no default language record. Compile child and mark it as such
+                        $compiledChild = $this->compileChild($result, $fieldName, $localizedUid);
+                        $compiledChild['inlineIsDanglingLocalization'] = true;
+                        $result['processedTca']['columns'][$fieldName]['children'][] = $compiledChild;
+                    } // Discard child if default language is missing and no showRemoved is set
+                }
+                if ($showPossible) {
+                    foreach ($connectedUidsOfDefaultLanguageRecord as $defaultLanguageUid) {
+                        // If there are still uids in $connectedUidsOfDefaultLanguageRecord, these are records that
+                        // exist in default language, but are not localized yet. Compile and mark those
+                        $compiledChild = $this->compileChild($result, $fieldName, $defaultLanguageUid);
+                        $compiledChild['inlineIsDefaultLanguage'] = true;
+                        $result['processedTca']['columns'][$fieldName]['children'][] = $compiledChild;
                     }
                 }
             }