[BUGFIX] Honor l18n_cfg settings in PageRepository 38/57038/8
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 22 May 2018 14:22:35 +0000 (16:22 +0200)
committerAndreas Wolf <andreas.wolf@typo3.org>
Sun, 3 Jun 2018 18:19:30 +0000 (20:19 +0200)
If a page record is fetched from the database, the PageRepository needs
to care about the l18n_cfg setting for this page.

Resolves: #85063
Releases: master, 8.7
Change-Id: Ib0338a4725a3b569b91f27baa3a59cabee6fe2fb
Reviewed-on: https://review.typo3.org/57038
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/frontend/Tests/Functional/Fixtures/pages.xml
typo3/sysext/frontend/Tests/Functional/Page/PageRepositoryTest.php

index 5c82755..2a62d44 100644 (file)
@@ -235,7 +235,7 @@ class PageRepository implements LoggerAwareInterface
      * The page record is either served from a first-level cache or loaded from the
      * database. If no page can be found, an empty array is returned.
      *
-     * Language overlay and versioning overlay are applied. Mount Point
+     * Language overlay and version overlay are applied. Mount Point
      * handling is not done, an overlaid Mount Point is not replaced.
      *
      * The result is conditioned by the public properties where_groupAccess
@@ -297,9 +297,16 @@ class PageRepository implements LoggerAwareInterface
 
         $row = $queryBuilder->execute()->fetch();
         if ($row) {
-            $this->versionOL('pages', $row);
-            if (is_array($row)) {
-                $result = $this->getPageOverlay($row);
+            $tsfe = $this->getTypoScriptFrontendController();
+            if ($tsfe->sys_language_uid > 0 || !GeneralUtility::hideIfDefaultLanguage($row['l18n_cfg'])) {
+                $this->versionOL('pages', $row);
+                if (is_array($row)) {
+                    $row = $this->getPageOverlay($row);
+
+                    if ($tsfe->sys_language_uid === 0 || isset($row['_PAGES_OVERLAY']) || !GeneralUtility::hideIfNotTranslated($row['l18n_cfg'])) {
+                        $result = $row;
+                    }
+                }
             }
         }
         $this->cache_getPage[$uid][$cacheKey] = $result;
@@ -727,6 +734,10 @@ class PageRepository implements LoggerAwareInterface
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
         $queryBuilder->getRestrictions()->removeAll();
 
+        // Always ensure fetching l18n_cfg for further processing
+        if ($fields !== '*' && !GeneralUtility::inList($fields, 'l18n_cfg')) {
+            $fields .= ',l18n_cfg';
+        }
         $res = $queryBuilder->select(...GeneralUtility::trimExplode(',', $fields, true))
             ->from('pages')
             ->where(
@@ -757,9 +768,9 @@ class PageRepository implements LoggerAwareInterface
 
             // Versioning Preview Overlay
             $this->versionOL('pages', $page, true);
-            // Skip if page got disabled due to version overlay
-            // (might be delete or move placeholder)
-            if (empty($page)) {
+            // Skip if page got disabled due to version overlay or default language should be hidden
+            // (might be deleted or move placeholder)
+            if (empty($page) || GeneralUtility::hideIfDefaultLanguage($page['l18n_cfg'])) {
                 continue;
             }
 
index abb60ee..40e7612 100644 (file)
     </pages>
 
     <pages>
+        <uid>501</uid>
+        <pid>1</pid>
+        <title>Localization 1-501</title>
+        <deleted>0</deleted>
+        <l18n_cfg>1</l18n_cfg>
+    </pages>
+    <pages>
+        <uid>502</uid>
+        <pid>1</pid>
+        <title>√úbersetzung 1-501</title>
+        <deleted>0</deleted>
+        <l10n_parent>501</l10n_parent>
+        <l18n_cfg>1</l18n_cfg>
+        <sys_language_uid>1</sys_language_uid>
+    </pages>
+
+    <pages>
         <uid>901</uid>
         <pid>0</pid>
         <l10n_parent>1</l10n_parent>
index b24b527..c99603a 100644 (file)
@@ -98,6 +98,15 @@ class PageRepositoryTest extends \TYPO3\TestingFramework\Core\Functional\Functio
     /**
      * @test
      */
+    public function getPageReturnsEmptyArrayWithHideIfDefaultLanguage()
+    {
+        $row = $this->pageRepo->getPage(501);
+        $this->assertSame([], $row);
+    }
+
+    /**
+     * @test
+     */
     public function getPageOverlayById()
     {
         $row = $this->pageRepo->getPageOverlay(1, 1);