Skip to content

Commit 4030561

Browse files
author
Maxime
authored
Merge pull request #87 from delyriand/fix/78-avoid-404-error
fix: avoid 404 error due to the Accept-Language header
2 parents 6d0d38d + 411043a commit 4030561

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

UPGRADE-2.0.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# Upgrade from 1.X to 2.X
1+
# Upgrade from 2.0.2 to 2.0.3
2+
3+
The `MonsieurBiz\SyliusCmsPagePlugin\Context\LastChanceLocaleContext` is now deprecated and will be removed in 2.1, use the `MonsieurBiz\SyliusCmsPagePlugin\Context\FindInRequestPathLocaleContext` instead.
4+
And the priority of this service has changed from `-127` to `35` to be higher than the `sylius.context.locale.request_header_based` service.
5+
6+
# Upgrade from 1.X to 2.0.X
27

38
In the 2.x we changed the route definition for the shop route.
49

@@ -32,4 +37,4 @@ monsieurbiz_cms_page_show:
3237
condition: "not(context.getPathInfo() matches '`^%sylius.security.api_route%`') and context.checkPageSlug(request)"
3338
```
3439
35-
We upgraded also the [Rich Editor to the 3.0 version](https://github.com/monsieurbiz/SyliusRichEditorPlugin/blob/3.x/UPGRADE-3.0.md).
40+
We upgraded also the [Rich Editor to the 3.0 version](https://github.com/monsieurbiz/SyliusRichEditorPlugin/blob/3.x/UPGRADE-3.0.md).

src/Context/LastChanceLocaleContext.php renamed to src/Context/FindInRequestPathLocaleContext.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
use Sylius\Component\Locale\Provider\LocaleProviderInterface;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020

21-
final class LastChanceLocaleContext implements LocaleContextInterface
21+
final class FindInRequestPathLocaleContext implements LocaleContextInterface
2222
{
2323
public function __construct(
2424
private RequestStack $requestStack,
25-
private LocaleProviderInterface $localeProvider
25+
private LocaleProviderInterface $localeProvider,
2626
) {
2727
}
2828

2929
public function getLocaleCode(): string
3030
{
3131
if (null === $request = $this->requestStack->getMainRequest()) {
32-
throw new LocaleNotFoundException('Main request not found, therefore no locale found…');
32+
throw new LocaleNotFoundException('No main request available.');
3333
}
34+
3435
$pathInfo = $request->getPathInfo();
3536
$availableLocaleCodes = $this->localeProvider->getAvailableLocalesCodes();
3637
$parts = explode('/', trim($pathInfo, '/'));
@@ -40,6 +41,6 @@ public function getLocaleCode(): string
4041
}
4142
}
4243

43-
return $this->localeProvider->getDefaultLocaleCode();
44+
throw new LocaleNotFoundException('No locale found in the request path.');
4445
}
4546
}

src/Resources/config/services.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ services:
1212
resource: '../../Controller'
1313
tags: ['controller.service_arguments']
1414

15-
# Let's try to find the locale one more time!
16-
MonsieurBiz\SyliusCmsPagePlugin\Context\LastChanceLocaleContext:
15+
# Let's try to find the locale from the request path.
16+
# The priority should be higher than the sylius.context.locale.request_header_based service to avoid 404 errors with
17+
MonsieurBiz\SyliusCmsPagePlugin\Context\FindInRequestPathLocaleContext:
1718
tags:
18-
- { name: sylius.context.locale, priority: -127 }
19+
- { name: sylius.context.locale, priority: 35 }
20+
21+
MonsieurBiz\SyliusCmsPagePlugin\Context\LastChanceLocaleContext:
22+
alias: MonsieurBiz\SyliusCmsPagePlugin\Context\FindInRequestPathLocaleContext
23+
deprecated:
24+
package: 'monsieurbiz/sylius-cms-page-plugin'
25+
version: '2.0.3'
26+
message: 'The "%alias_id%" service alias is deprecated and will be removed in 2.1. Use "MonsieurBiz\SyliusCmsPagePlugin\Context\FindInRequestPathLocaleContext" instead.'
1927

2028
# Menu item in admin panel
2129
MonsieurBiz\SyliusCmsPagePlugin\Listener\AdminMenuListener:

0 commit comments

Comments
 (0)