[BUGFIX] Add language parameter to preview url in list module 41/52341/9
authorGianluigi Martino <gmartino27@gmail.com>
Mon, 3 Apr 2017 14:18:22 +0000 (16:18 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 24 Jan 2018 19:23:14 +0000 (20:23 +0100)
The language parameter was not set if the "View webpage" button was used
within the context menu of an element in the page module or the
"View webpage" button in the record list of a desired language.

Resolves: #80599
Releases: master, 8.7
Change-Id: I40fb5749cbd56c0075a8aa2c5ec3b2d8dea66501
Reviewed-on: https://review.typo3.org/52341
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Reiner Teubner <reiner.teubner@me.com>
Tested-by: Reiner Teubner <reiner.teubner@me.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/backend/Classes/ContextMenu/ItemProviders/RecordProvider.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 89ac092..b369351 100644 (file)
@@ -416,12 +416,22 @@ class RecordProvider extends AbstractProvider
      */
     protected function getViewLink(): string
     {
-        $anchorSection = $this->table === 'tt_content' ? '#c' . $this->record['uid'] : '';
+        $anchorSection = '';
+        $additionalParams = '';
+        if ($this->table === 'tt_content') {
+            $anchorSection = '#c' . $this->record['uid'];
+            $language = (int)$this->record[$GLOBALS['TCA']['tt_content']['ctrl']['languageField']];
+            if ($language > 0) {
+                $additionalParams = '&L=' . $language;
+            }
+        }
         $javascriptLink = BackendUtility::viewOnClick(
             $this->getPreviewPid(),
             '',
             null,
-            $anchorSection
+            $anchorSection,
+            '',
+            $additionalParams
         );
         $extractedLink = '';
         if (preg_match('/window\\.open\\(\'([^\']+)\'/i', $javascriptLink, $match)) {
index 0c4a35b..b2fba7c 100644 (file)
@@ -1298,17 +1298,29 @@ class DatabaseRecordList
     protected function getOnClickForRow(string $table, array $row): string
     {
         if ($table === 'tt_content') {
-            // Link to a content element
-            $onClick = BackendUtility::viewOnClick($this->id, '', null, '#' . $row['uid']);
+            // Link to a content element, possibly translated and with anchor
+            $additionalParams = '';
+            $language = (int)$row[$GLOBALS['TCA']['tt_content']['ctrl']['languageField']];
+            if ($language > 0) {
+                $additionalParams = '&L=' . $language;
+            }
+            $onClick = BackendUtility::viewOnClick(
+                $this->id,
+                '',
+                null,
+                '#c' . $row['uid'],
+                '',
+                $additionalParams
+            );
         } elseif ($table === 'pages' && $row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']] > 0) {
-            // Link to a page translation
+            // Link to a page translation needs uid of default language page as id
             $onClick = BackendUtility::viewOnClick(
                 $row[$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']],
                 '',
                 null,
                 '',
                 '',
-                '&L=' . $row[$GLOBALS['TCA']['pages']['ctrl']['languageField']]
+                '&L=' . (int)$row[$GLOBALS['TCA']['pages']['ctrl']['languageField']]
             );
         } else {
             // Link to a page in the default language