From bd1d1212d8e00b26f9f4a0fe2992b6a61dd85120 Mon Sep 17 00:00:00 2001
From: Daniel Goerz <daniel.goerz@posteo.de>
Date: Fri, 26 Oct 2018 15:24:51 +0200
Subject: [PATCH] [BUGFIX] Always set overrideVals when editing a page

Resolves: #86754
Releases: master
Change-Id: I2bb3226595e53ed993e0114130123e4f87f1603b
Reviewed-on: https://review.typo3.org/58712
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 .../ContextMenu/ItemProviders/PageProvider.php      |  5 +++++
 .../Classes/Controller/EditDocumentController.php   | 13 +++++++++++--
 .../sysext/backend/Classes/View/PageLayoutView.php  |  1 +
 .../Private/TypeScript/ContextMenuActions.ts        | 13 ++++++++++++-
 .../Public/JavaScript/ContextMenuActions.js         |  2 +-
 .../Classes/RecordList/DatabaseRecordList.php       |  2 ++
 6 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/PageProvider.php b/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/PageProvider.php
index 12161050d9ec..2ceb7a83a246 100644
--- a/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/PageProvider.php
+++ b/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/PageProvider.php
@@ -466,6 +466,11 @@ class PageProvider extends RecordProvider
                 'data-pages-new-multiple-url' => (string)$uriBuilder->buildUriFromRoute('pages_new', ['id' => $this->record['uid']]),
             ];
         }
+        if ($itemName === 'edit') {
+            $attributes = [
+                'data-pages-language-uid' => $this->record['sys_language_uid']
+            ];
+        }
         return $attributes;
     }
 
diff --git a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php
index f6ba2fd931c4..97293d9ebda0 100644
--- a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php
+++ b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php
@@ -2313,10 +2313,19 @@ class EditDocumentController
                                 $addOption = false;
                             }
                         } else {
-                            $href = (string)$uriBuilder->buildUriFromRoute('record_edit', [
+                            $params = [
                                 'edit[' . $table . '][' . $rowsByLang[$languageId]['uid'] . ']' => 'edit',
                                 'returnUrl' => $this->retUrl
-                            ]);
+                            ];
+                            if ($table === 'pages') {
+                                // Disallow manual adjustment of the language field for pages
+                                $params['overrideVals'] = [
+                                    'pages' => [
+                                        'sys_language_uid' => $languageId
+                                    ]
+                                ];
+                            }
+                            $href = (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
                         }
                         if ($addOption) {
                             $menuItem = $languageMenu->makeMenuItem()
diff --git a/typo3/sysext/backend/Classes/View/PageLayoutView.php b/typo3/sysext/backend/Classes/View/PageLayoutView.php
index b664bfda5d13..2972577387fa 100644
--- a/typo3/sysext/backend/Classes/View/PageLayoutView.php
+++ b/typo3/sysext/backend/Classes/View/PageLayoutView.php
@@ -1327,6 +1327,7 @@ class PageLayoutView implements LoggerAwareInterface
                                 $pageLocalizationRecord['uid'] => 'edit'
                             ]
                         ],
+                        // Disallow manual adjustment of the language field for pages
                         'overrideVals' => [
                             'pages' => [
                                 'sys_language_uid' => $lP
diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/ContextMenuActions.ts b/typo3/sysext/backend/Resources/Private/TypeScript/ContextMenuActions.ts
index 3736b45b630a..f82eedad642f 100644
--- a/typo3/sysext/backend/Resources/Private/TypeScript/ContextMenuActions.ts
+++ b/typo3/sysext/backend/Resources/Private/TypeScript/ContextMenuActions.ts
@@ -34,8 +34,19 @@ class ContextMenuActions {
    * @param {number} uid
    */
   public static editRecord(table: string, uid: number): void {
+    let overrideVals = '',
+      pageLanguageId = $(this).data('pages-language-uid');
+
+    if (pageLanguageId) {
+      // Disallow manual adjustment of the language field for pages
+      overrideVals = '&overrideVals[pages][sys_language_uid]=' + pageLanguageId;
+    }
+
     Viewport.ContentContainer.setUrl(
-      top.TYPO3.settings.FormEngine.moduleUrl + '&edit[' + table + '][' + uid + ']=edit&returnUrl=' + ContextMenuActions.getReturnUrl()
+      top.TYPO3.settings.FormEngine.moduleUrl
+        + '&edit[' + table + '][' + uid + ']=edit'
+        + overrideVals
+        + '&returnUrl=' + ContextMenuActions.getReturnUrl()
     );
   }
 
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/ContextMenuActions.js b/typo3/sysext/backend/Resources/Public/JavaScript/ContextMenuActions.js
index b1a00fdadb76..ff33703faa9e 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/ContextMenuActions.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/ContextMenuActions.js
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","./Enum/Severity","jquery","./InfoWindow","./Modal","./ModuleMenu","./Viewport"],function(e,t,n,o,r,a,i,s){"use strict";return function(){function e(){}return e.getReturnUrl=function(){return top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search)},e.editRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+t+"]["+n+"]=edit&returnUrl="+e.getReturnUrl())},e.viewRecord=function(e,t){var n=o(this).data("preview-url");n&&window.open(n,"newTYPO3frontendWindow").focus()},e.openInfoPopUp=function(e,t){r.showItem(e,t)},e.mountAsTreeRoot=function(e,t){"pages"===e&&s.NavigationContainer.PageTree.setTemporaryMountPoint(t)},e.newPageWizard=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.NewRecord.moduleUrl+"&id="+n+"&pagesOnly=1&returnUrl="+e.getReturnUrl())},e.newContentWizard=function(t,r){var i=o(this),s=i.data("new-wizard-url");s&&(s+="&returnUrl="+e.getReturnUrl(),a.advanced({title:i.data("title"),type:a.types.ajax,size:a.sizes.medium,content:s,severity:n.SeverityEnum.notice}))},e.newRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+t+"][-"+n+"]=new&returnUrl="+e.getReturnUrl())},e.openHistoryPopUp=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.RecordHistory.moduleUrl+"&element="+t+":"+n+"&returnUrl="+e.getReturnUrl())},e.openListModule=function(e,t){var n="pages"===e?t:o(this).data("page-uid");i.App.showModule("web_list","id="+n)},e.pagesSort=function(e,t){var n=o(this).data("pages-sort-url");n&&s.ContentContainer.setUrl(n)},e.pagesNewMultiple=function(e,t){var n=o(this).data("pages-new-multiple-url");n&&s.ContentContainer.setUrl(n)},e.disableRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+n+"][hidden]=1&redirect="+e.getReturnUrl()).done(function(){s.NavigationContainer.PageTree.refreshTree()})},e.enableRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+n+"][hidden]=0&redirect="+e.getReturnUrl()).done(function(){s.NavigationContainer.PageTree.refreshTree()})},e.deleteRecord=function(t,r){var i=o(this);a.confirm(i.data("title"),i.data("message"),n.SeverityEnum.warning,[{text:o(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:o(this).data("button-ok-text")||TYPO3.lang["button.delete"]||"Delete",btnClass:"btn-warning",name:"delete"}]).on("button.clicked",function(n){"delete"===n.target.getAttribute("name")&&s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&redirect="+e.getReturnUrl()+"&cmd["+t+"]["+r+"][delete]=1").done(function(){if("pages"===t&&s.NavigationContainer.PageTree){if(r===top.fsMod.recentIds.web){var e=s.NavigationContainer.PageTree.instance.nodes[0];s.NavigationContainer.PageTree.selectNode(e)}s.NavigationContainer.PageTree.refreshTree()}}),a.dismiss()})},e.copy=function(t,n){var r=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+n+"]=1&CB[setCopyMode]=1";o.ajax(r).always(function(){e.triggerRefresh(s.ContentContainer.get().location.href)})},e.clipboardRelease=function(t,n){var r=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+n+"]=0";o.ajax(r).always(function(){e.triggerRefresh(s.ContentContainer.get().location.href)})},e.cut=function(t,n){var r=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+n+"]=1&CB[setCopyMode]=0";o.ajax(r).always(function(){e.triggerRefresh(s.ContentContainer.get().location.href)})},e.triggerRefresh=function(e){-1===e.indexOf("record%2Fedit")&&s.ContentContainer.refresh(!0)},e.clearCache=function(e,t){var n=top.TYPO3.settings.WebLayout.moduleUrl+"&id="+t+"&clear_cache=1";o.ajax(n)},e.pasteAfter=function(t,n){e.pasteInto.bind(o(this))(t,-n)},e.pasteInto=function(t,r){var i=o(this),l=function(){var n="&CB[paste]="+t+"%7C"+r+"&CB[pad]=normal&redirect="+e.getReturnUrl();s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+n).done(function(){"pages"===t&&s.NavigationContainer.PageTree&&s.NavigationContainer.PageTree.refreshTree()})};i.data("title")?a.confirm(i.data("title"),i.data("message"),n.SeverityEnum.warning,[{text:o(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:o(this).data("button-ok-text")||TYPO3.lang["button.ok"]||"OK",btnClass:"btn-warning",name:"ok"}]).on("button.clicked",function(e){"ok"===e.target.getAttribute("name")&&l(),a.dismiss()}):l()},e}()});
\ No newline at end of file
+define(["require","exports","./Enum/Severity","jquery","./InfoWindow","./Modal","./ModuleMenu","./Viewport"],function(e,t,n,r,o,a,i,s){"use strict";return function(){function e(){}return e.getReturnUrl=function(){return top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search)},e.editRecord=function(t,n){var o="",a=r(this).data("pages-language-uid");a&&(o="&overrideVals[pages][sys_language_uid]="+a),s.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+t+"]["+n+"]=edit"+o+"&returnUrl="+e.getReturnUrl())},e.viewRecord=function(e,t){var n=r(this).data("preview-url");n&&window.open(n,"newTYPO3frontendWindow").focus()},e.openInfoPopUp=function(e,t){o.showItem(e,t)},e.mountAsTreeRoot=function(e,t){"pages"===e&&s.NavigationContainer.PageTree.setTemporaryMountPoint(t)},e.newPageWizard=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.NewRecord.moduleUrl+"&id="+n+"&pagesOnly=1&returnUrl="+e.getReturnUrl())},e.newContentWizard=function(t,o){var i=r(this),s=i.data("new-wizard-url");s&&(s+="&returnUrl="+e.getReturnUrl(),a.advanced({title:i.data("title"),type:a.types.ajax,size:a.sizes.medium,content:s,severity:n.SeverityEnum.notice}))},e.newRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+t+"][-"+n+"]=new&returnUrl="+e.getReturnUrl())},e.openHistoryPopUp=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.RecordHistory.moduleUrl+"&element="+t+":"+n+"&returnUrl="+e.getReturnUrl())},e.openListModule=function(e,t){var n="pages"===e?t:r(this).data("page-uid");i.App.showModule("web_list","id="+n)},e.pagesSort=function(e,t){var n=r(this).data("pages-sort-url");n&&s.ContentContainer.setUrl(n)},e.pagesNewMultiple=function(e,t){var n=r(this).data("pages-new-multiple-url");n&&s.ContentContainer.setUrl(n)},e.disableRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+n+"][hidden]=1&redirect="+e.getReturnUrl()).done(function(){s.NavigationContainer.PageTree.refreshTree()})},e.enableRecord=function(t,n){s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+n+"][hidden]=0&redirect="+e.getReturnUrl()).done(function(){s.NavigationContainer.PageTree.refreshTree()})},e.deleteRecord=function(t,o){var i=r(this);a.confirm(i.data("title"),i.data("message"),n.SeverityEnum.warning,[{text:r(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:r(this).data("button-ok-text")||TYPO3.lang["button.delete"]||"Delete",btnClass:"btn-warning",name:"delete"}]).on("button.clicked",function(n){"delete"===n.target.getAttribute("name")&&s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&redirect="+e.getReturnUrl()+"&cmd["+t+"]["+o+"][delete]=1").done(function(){if("pages"===t&&s.NavigationContainer.PageTree){if(o===top.fsMod.recentIds.web){var e=s.NavigationContainer.PageTree.instance.nodes[0];s.NavigationContainer.PageTree.selectNode(e)}s.NavigationContainer.PageTree.refreshTree()}}),a.dismiss()})},e.copy=function(t,n){var o=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+n+"]=1&CB[setCopyMode]=1";r.ajax(o).always(function(){e.triggerRefresh(s.ContentContainer.get().location.href)})},e.clipboardRelease=function(t,n){var o=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+n+"]=0";r.ajax(o).always(function(){e.triggerRefresh(s.ContentContainer.get().location.href)})},e.cut=function(t,n){var o=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+n+"]=1&CB[setCopyMode]=0";r.ajax(o).always(function(){e.triggerRefresh(s.ContentContainer.get().location.href)})},e.triggerRefresh=function(e){-1===e.indexOf("record%2Fedit")&&s.ContentContainer.refresh(!0)},e.clearCache=function(e,t){var n=top.TYPO3.settings.WebLayout.moduleUrl+"&id="+t+"&clear_cache=1";r.ajax(n)},e.pasteAfter=function(t,n){e.pasteInto.bind(r(this))(t,-n)},e.pasteInto=function(t,o){var i=r(this),l=function(){var n="&CB[paste]="+t+"%7C"+o+"&CB[pad]=normal&redirect="+e.getReturnUrl();s.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+n).done(function(){"pages"===t&&s.NavigationContainer.PageTree&&s.NavigationContainer.PageTree.refreshTree()})};i.data("title")?a.confirm(i.data("title"),i.data("message"),n.SeverityEnum.warning,[{text:r(this).data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:r(this).data("button-ok-text")||TYPO3.lang["button.ok"]||"OK",btnClass:"btn-warning",name:"ok"}]).on("button.clicked",function(e){"ok"===e.target.getAttribute("name")&&l(),a.dismiss()}):l()},e}()});
\ No newline at end of file
diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
index 9b09e439456f..264d6a8f1756 100644
--- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
+++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
@@ -1988,6 +1988,8 @@ class DatabaseRecordList
             $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
             $iconIdentifier = 'actions-open';
             if ($table === 'pages') {
+                // Disallow manual adjustment of the language field for pages
+                $params .= '&overrideVals[pages][sys_language_uid]=' . (int)$row[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
                 $iconIdentifier = 'actions-page-open';
             }
             $overlayIdentifier = !$this->isEditable($table) ? 'overlay-readonly' : null;
-- 
GitLab