Skip to content

Commit

Permalink
Fix mishandled language change
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Jun 16, 2024
1 parent 1187cfd commit 221aad5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions formwork/src/Pages/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ public function setLanguage(Language|string|null $language): void
return;
}

if ($this->languages()->current() !== null && $language !== null && $this->languages()->current()->code() !== ($code = $language->code())) {
if (!$this->languages()->available()->has($code)) {
if ($this->languages()->current()?->code() !== ($code = $language?->code())) {
if ($code !== null && !$this->languages()->available()->has($code)) {
throw new InvalidArgumentException(sprintf('Invalid page language "%s"', $code));
}
$this->reload(['language' => $language]);
Expand Down
3 changes: 3 additions & 0 deletions formwork/src/Panel/Controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ public function edit(RouteParams $routeParams): Response
}

// Redirect to avoid ERR_CACHE_MISS
if ($routeParams->has('language')) {
return $this->redirect($this->generateRoute('panel.pages.edit.lang', ['page' => $page->route(), 'language' => $routeParams->get('language')]));
}
return $this->redirect($this->generateRoute('panel.pages.edit', ['page' => $page->route()]));
}

Expand Down

0 comments on commit 221aad5

Please sign in to comment.