[BUGFIX] Language selector not shown in default page without translation 74/56774/3
authorPatrick Broens <patrick@patrickbroens.nl>
Sat, 21 Apr 2018 08:55:13 +0000 (10:55 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 22 Jun 2018 23:14:38 +0000 (01:14 +0200)
When editing a page, the language selector in the upper left corner is
not visible when the page is in the default language and does not have a
translation yet. When the page has at least one translation, the language
selector is visible, which is inconsistent behaviour.

This patch adds a check for the table. When the languages for the page
table are fetched, all languages are fetched.

Resolves: #84834
Releases: master
Change-Id: Ib482fecef6cbddcbf945e0e4d944e181c27a115c
Reviewed-on: https://review.typo3.org/56774
Reviewed-by: Sebastian Hofer <sebastian.hofer@marit.ag>
Tested-by: Sebastian Hofer <sebastian.hofer@marit.ag>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Torben Hansen <derhansen@gmail.com>
Tested-by: Torben Hansen <derhansen@gmail.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Christian Hellmund <developement@hellmund.eu>
Reviewed-by: Florian Mast <flo.mast@web.de>
Tested-by: Florian Mast <flo.mast@web.de>
Reviewed-by: Ruslan Steiger <steiger.ruslan@gmail.com>
Tested-by: Ruslan Steiger <steiger.ruslan@gmail.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php

index f34e74a..9fa0e1b 100644 (file)
@@ -2233,9 +2233,12 @@ class EditDocumentController
             if ($table === 'pages') {
                 $row = BackendUtility::getRecord($table, $uid, $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']);
                 // Ensure the check is always done against the default language page
-                $langRows = $this->getLanguages((int)($row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']] ?: $uid));
+                $langRows = $this->getLanguages(
+                    (int)$row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']] ?: $uid,
+                    $table
+                );
             } else {
-                $langRows = $this->getLanguages((int)$pid);
+                $langRows = $this->getLanguages((int)$pid, $table);
             }
             // Page available in other languages than default language?
             if (is_array($langRows) && count($langRows) > 1) {
@@ -2430,9 +2433,10 @@ class EditDocumentController
      * @param int $id Page id: If zero, the query will select all sys_language records from root level which are NOT
      *                hidden. If set to another value, the query will select all sys_language records that has a
      *                translation record on that page (and is not hidden, unless you are admin user)
+     * @param string $table For pages we want all languages, for other records the languages of the page translations
      * @return array Language records including faked record for default language
      */
-    public function getLanguages(int $id): array
+    public function getLanguages(int $id, string $table = ''): array
     {
         // Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
         $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
@@ -2481,12 +2485,7 @@ class EditDocumentController
                 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
             }
 
-            // Add join with pages translations to only show active languages
-            $queryBuilder->from('pages', 'o')
-                ->where(
-                    $queryBuilder->expr()->eq('o.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'], $queryBuilder->quoteIdentifier('s.uid')),
-                    $queryBuilder->expr()->eq('o.' . $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'], $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT))
-                );
+            $this->joinPagesTranslationsForActiveLanguage($queryBuilder, $table, $id);
         }
 
         $result = $queryBuilder->execute();
@@ -2498,6 +2497,29 @@ class EditDocumentController
     }
 
     /**
+     * @param QueryBuilder $queryBuilder
+     * @param string $table
+     * @param int $id
+     */
+    public function joinPagesTranslationsForActiveLanguage(QueryBuilder $queryBuilder, string $table, int $id)
+    {
+        // Add join with pages translations to only show active languages
+        if ($table !== 'pages') {
+            $queryBuilder->from('pages', 'o')
+                         ->where(
+                             $queryBuilder->expr()->eq(
+                                 'o.' . $GLOBALS['TCA']['pages']['ctrl']['languageField'],
+                                 $queryBuilder->quoteIdentifier('s.uid')
+                             ),
+                             $queryBuilder->expr()->eq(
+                                 'o.' . $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
+                                 $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
+                             )
+                         );
+        }
+    }
+
+    /**
      * Fix $this->editconf if versioning applies to any of the records
      *
      * @param array|bool $mapArray Mapping between old and new ids if auto-versioning has been performed.