Skip to content

Commit 3e3efe3

Browse files
committed
Improve locale matching in FrontendPageController
The code was updated to more effectively match the request locale with the allowed locales in the FrontendPageController. In cases where there's no match, the first allowed locale is employed. This change enhances the readability and clarity in handling locale-related variables. Additionally, unused 'ContentSecurityPolicyHelper' was removed and default status updated to 'status_published'.
1 parent 68a3722 commit 3e3efe3

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/Controller/FrontendPageController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,23 @@ public function adminNavbarAction(Request $request, $page_id = null)
522522
$livePath = null;
523523
$editPath = null;
524524
$liveRoute = null;
525-
$language = $request->getLocale();
525+
$locale = $request->getLocale();
526+
$shortLocale = substr($locale, 0, 2);
527+
528+
$allowedLocales = $this->getParameter('networking_init_cms.page.languages');
529+
530+
$localeMatched = false;
531+
532+
foreach ($allowedLocales as $allowedLocale) {
533+
if ($allowedLocale['locale'] == $request->getLocale() || $shortLocale == $allowedLocale['locale']) {
534+
$locale = $allowedLocale['locale'];
535+
$localeMatched = true;
536+
}
537+
}
538+
539+
if (!$localeMatched) {
540+
$locale = $allowedLocales[0]['locale'];
541+
}
526542

527543
if ($entity instanceof VersionableInterface) {
528544
if ($snapShot = $entity->getSnapshot()) {

0 commit comments

Comments
 (0)