[BUGFIX] Show all content elements with mod.web_layout.defLangBinding 54/54654/11
authorNicole Cordes <typo3@cordes.co>
Sat, 12 May 2018 10:39:52 +0000 (12:39 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Sat, 12 May 2018 10:58:53 +0000 (12:58 +0200)
The option is meant to show translated content elements
alligned with their translation parent element (connected mode).

However this also made content elements diasppear, which were
added individually in a language (free mode).

With this change, elements for a language in free mode
are also shown, when the option is set.

Resolves: #62550
Releases: master, 8.7
Change-Id: I96f754ecf4ddb98f22d0d8c7d7da6001fa774d6b
Reviewed-on: https://review.typo3.org/54654
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/backend/Classes/View/PageLayoutView.php

index 6057547..3aa3996 100644 (file)
@@ -1014,7 +1014,7 @@ class PageLayoutView implements LoggerAwareInterface
                                 $defaultLanguageElementsByColumn[$columnId][] = ($row['_ORIG_uid'] ?? $row['uid']);
                             }
                             $editUidList .= $row['uid'] . ',';
-                            $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
+                            $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0 && $this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP);
                             if (!$this->tt_contentConfig['languageMode']) {
                                 $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
                             }
@@ -1090,7 +1090,7 @@ class PageLayoutView implements LoggerAwareInterface
                             }
                             $singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
                             if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
-                                $defLangBinding[$columnId][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
+                                $defLangBinding[$columnId][$lP][$row[$lP ? 'l18n_parent' : 'uid'] ?: $row['uid']] = $singleElementHTML;
                             } else {
                                 $content[$columnId] .= $singleElementHTML;
                             }
@@ -1405,16 +1405,27 @@ class PageLayoutView implements LoggerAwareInterface
                     $out .= '<td valign="top" data-colpos="' . $cKey . '" class="t3-grid-cell t3-page-column t3js-page-column t3js-page-lang-column t3js-page-lang-column-' . $languageId . '">' . $columnContent . '</td>';
                 }
                 $out .= '</tr>';
-                if ($this->defLangBinding) {
-                    // "defLangBinding" mode
-                    foreach ($defaultLanguageElementsByColumn[$cKey] as $defUid) {
+                if ($this->defLangBinding && !empty($defLangBinding[$cKey])) {
+                    $maxItemsCount = max(array_map('count', $defLangBinding[$cKey]));
+                    for ($i = 0; $i < $maxItemsCount; $i++) {
+                        $defUid = $defaultLanguageElementsByColumn[$cKey][$i] ?? 0;
                         $cCont = [];
                         foreach ($langListArr as $lP) {
-                            $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
-                                $this->getNonTranslatedTTcontentUids([$defUid], $id, $lP),
-                                $lP,
-                                $cKey
-                            );
+                            if ($lP > 0
+                                && is_array($defLangBinding[$cKey][$lP])
+                                && !$this->checkIfTranslationsExistInLanguage($defaultLanguageElementsByColumn[$cKey], $lP)
+                                && count($defLangBinding[$cKey][$lP]) > $i
+                            ) {
+                                $slice = array_slice($defLangBinding[$cKey][$lP], $i, 1);
+                                $element = $slice[0] ?? '';
+                            } else {
+                                $element = $defLangBinding[$cKey][$lP][$defUid] ?? '';
+                            }
+                            $cCont[] = $element . $this->newLanguageButton(
+                                    $this->getNonTranslatedTTcontentUids([$defUid], $id, $lP),
+                                    $lP,
+                                    $cKey
+                                );
                         }
                         $out .= '
                         <tr>
@@ -2411,7 +2422,7 @@ class PageLayoutView implements LoggerAwareInterface
                 $allowTranslate = false;
             }
             if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
-                $allowCopy = false;
+                $allowCopy = !$this->languageHasTranslationsCache[$lP]['hasTranslations'];
             }
         }
 
@@ -2974,8 +2985,11 @@ class PageLayoutView implements LoggerAwareInterface
                     }
                 }
             }
+            if (!isset($this->languageHasTranslationsCache[$language])) {
+                $this->languageHasTranslationsCache[$language]['hasTranslations'] = false;
+            }
             // Check whether we have a mix of both
-            if ($this->languageHasTranslationsCache[$language]['hasStandAloneContent']
+            if (isset($this->languageHasTranslationsCache[$language]['hasStandAloneContent'])
                 && $this->languageHasTranslationsCache[$language]['hasTranslations']
             ) {
                 $this->languageHasTranslationsCache[$language]['mode'] = 'mixed';
@@ -2990,10 +3004,8 @@ class PageLayoutView implements LoggerAwareInterface
                 $queue->addMessage($message);
             }
         }
-        if ($this->languageHasTranslationsCache[$language]['hasTranslations']) {
-            return true;
-        }
-        return false;
+
+        return $this->languageHasTranslationsCache[$language]['hasTranslations'];
     }
 
     /**
@@ -4275,7 +4287,7 @@ class PageLayoutView implements LoggerAwareInterface
         $code = '';
         if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
             if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
-                //     Reverse
+                // Reverse
                 $theData = [];
                 $titleCol = $this->fieldArray[0];
                 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
@@ -4284,7 +4296,7 @@ class PageLayoutView implements LoggerAwareInterface
             return [1, $code];
         }
         if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
-            //         Forward
+            // Forward
             $theData = [];
             $titleCol = $this->fieldArray[0];
             $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);