3030use TYPO3 \CMS \Core \Database \Query \Restriction \WorkspaceRestriction ;
3131use TYPO3 \CMS \Core \Domain \Record ;
3232use TYPO3 \CMS \Core \Domain \RecordFactory ;
33+ use TYPO3 \CMS \Core \Http \HtmlResponse ;
34+ use TYPO3 \CMS \Core \Http \ImmediateResponseException ;
3335use TYPO3 \CMS \Core \Imaging \IconFactory ;
3436use TYPO3 \CMS \Core \Imaging \IconSize ;
3537use TYPO3 \CMS \Core \Information \Typo3Version ;
6163use function is_array ;
6264use function sprintf ;
6365
66+ use const JSON_UNESCAPED_SLASHES ;
67+
6468/**
6569 * @phpstan-type LanguageRef -1|0|positive-int
6670 */
@@ -174,19 +178,13 @@ public function __invoke(ServerRequestInterface $request): ResponseInterface
174178 $ view ->getDocHeaderComponent ()->setPageBreadcrumb ($ this ->pageRecord ->getRawRecord ()->toArray ());
175179 }
176180
177- $ iframeUrl = $ this ->iframeUrl ($ request );
181+ $ siteLanguage = $ this ->selectedLanguages [0 ];
182+ $ iframeUrl = $ this ->iframeUrl ($ request , $ siteLanguage );
178183 $ view ->assignMultiple ([
179184 'pageId ' => $ this ->pageRecord ->getUid (),
180185 'iframeSrc ' => $ iframeUrl ,
181186 ]);
182187
183- $ returnUrl = GeneralUtility::sanitizeLocalUrl (
184- (string )($ request ->getQueryParams ()['returnUrl ' ] ?? '' ),
185- ) ?: $ this ->uriBuilder ->buildUriFromRoute ('web_edit ' );
186-
187- // Always add rootPageId as additional field to have a reference for new records
188- $ view ->assign ('returnUrl ' , $ returnUrl );
189-
190188 $ this ->makeButtons ($ view , $ request );
191189 $ this ->makeLanguageMenu ($ view , $ request );
192190
@@ -200,16 +198,40 @@ public function __invoke(ServerRequestInterface $request): ResponseInterface
200198 return $ view ->renderResponse ('PageEdit ' );
201199 }
202200
203- private function iframeUrl (ServerRequestInterface $ request ): UriInterface
201+ private function iframeUrl (ServerRequestInterface $ request, SiteLanguage $ siteLanguage ): UriInterface
204202 {
205- return $ this ->site ->getRouter ()->generateUri (
206- $ this ->pageRecord ->getUid (),
207- [
208- ...$ request ->getQueryParams ()['params ' ] ?? [],
209- '_language ' => $ this ->selectedLanguages [0 ]->getLanguageId (),
210- 'editMode ' => 1 ,
211- ],
212- );
203+ $ parameters = [
204+ ...$ request ->getQueryParams ()['params ' ] ?? [],
205+ '_language ' => $ siteLanguage ->getLanguageId (),
206+ 'editMode ' => 1 ,
207+ ];
208+
209+ $ uri = $ this ->site ->getRouter ()->generateUri ($ this ->pageRecord ->getUid (), $ parameters );
210+
211+ if (
212+ $ uri ->getScheme () === $ request ->getUri ()->getScheme ()
213+ && $ uri ->getHost () === $ request ->getUri ()->getHost ()
214+ && $ uri ->getPort () === $ request ->getUri ()->getPort ()
215+ ) {
216+ // if same origin, we can return the Uri
217+ return $ uri ;
218+ }
219+
220+ // redirect to the correct backend origin:
221+ $ backendUrl = $ this ->uriBuilder
222+ ->buildUriFromRoute (
223+ 'web_edit ' ,
224+ [
225+ 'id ' => $ this ->pageRecord ->getUid (),
226+ 'languages ' => array_map (fn (SiteLanguage $ siteLanguage ): int => $ siteLanguage ->getLanguageId (), $ this ->selectedLanguages ),
227+ ],
228+ referenceType: UriBuilder::ABSOLUTE_URL ,
229+ )
230+ ->withScheme ($ uri ->getScheme ())
231+ ->withHost ($ uri ->getHost ())
232+ ->withPort ($ uri ->getPort ());
233+ $ html = '<script>window.top.location.href = ' . json_encode ((string )$ backendUrl , JSON_UNESCAPED_SLASHES ) . ';</script> ' ;
234+ throw new ImmediateResponseException (new HtmlResponse ($ html , 406 ), 3234807219 );
213235 }
214236
215237 private function makeButtons (ModuleTemplate $ view , ServerRequestInterface $ request ): void
0 commit comments