Skip to content

Commit 6c16a3e

Browse files
authored
Merge pull request #13 from antistatique/1.0.x--support-drupal-10
2 parents 53d9588 + 90369b8 commit 6c16a3e

10 files changed

+824
-19
lines changed

.github/workflows/ci.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ on:
55
- cron: '0 0 * * THU'
66

77
jobs:
8+
89
tests:
910
name: Tests
1011

1112
runs-on: ubuntu-latest
1213

1314
strategy:
1415
matrix:
15-
drupal_version: ['9.3', '9.4', '9.5']
16+
drupal_version: ['9.3', '9.4', '9.5', '10.0']
1617
module: ['home_redirect_lang']
1718
experimental: [ false ]
1819

@@ -32,7 +33,7 @@ jobs:
3233

3334
strategy:
3435
matrix:
35-
drupal_version: ['9.3', '9.4', '9.5']
36+
drupal_version: ['9.3', '9.4', '9.5', '10.0']
3637
module: ['home_redirect_lang']
3738
experimental: [ false ]
3839

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Fixed
99
- fix Issue #3320300: Avoid "Uncaught ReferenceError: Drupal is not defined" for anonymous users
10+
- fix parse_url(): passing null to parameter #1 () of type string is deprecated
11+
- fix Drupal 10 (Symfony 6) Kernel Event Priorities
1012

1113
### Removed
1214
- remove satackey/action-docker-layer-caching on Github Actions
15+
- drop support of drupal below 9.3.x
1316

1417
### Added
1518
- add coverage for Drupal 9.3, 9.4 & 9.5
16-
- drop support of drupal below 9.3.x
19+
- add official support of drupal 9.5 & 10.0
20+
21+
### Changed
22+
- re-enable PHPUnit Symfony Deprecation notice
1723

1824
## [1.0.0-alpha1] - 2022-09-22
1925
### Added

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ First, you will need to have the following tools installed
2323
globally on your environment:
2424

2525
* drush
26-
* Latest dev release of Drupal 9.x.
26+
* Latest dev release of Drupal 9.x/10.x.
2727
* docker
2828
* docker-compose
2929

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG BASE_IMAGE_TAG
55
ENV BASE_IMAGE_TAG=${BASE_IMAGE_TAG}
66

77
# Disable deprecation notice.
8-
ENV SYMFONY_DEPRECATIONS_HELPER=disabled
8+
# ENV SYMFONY_DEPRECATIONS_HELPER=disabled
99

1010
# Register the Drupal and DrupalPractice Standard with PHPCS.
1111
#RUN ./vendor/bin/phpcs --config-set installed_paths \

src/EventSubscriber/HomepageBrowserLanguageRedirection.php

+22-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
*/
2626
class HomepageBrowserLanguageRedirection implements EventSubscriberInterface {
2727

28+
/**
29+
* The Browser Redirection must be triggered before the Cookie redirection.
30+
*
31+
* The value here must be higher than
32+
* {@HomepageCookieLanguageRedirection::PRIORITY}.
33+
*
34+
* This needs to run after \Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest(),
35+
* which has a priority of 32.
36+
* This needs to run before \Drupal\home_redirect_lang\EventSubscriber\HomepageCookieLanguageRedirection::redirectPreferredLanguage(),
37+
* which has a priority of 30.
38+
*
39+
* @var int
40+
*/
41+
private const PRIORITY = 31;
42+
2843
/**
2944
* Symfony\Component\HttpFoundation\RequestStack definition.
3045
*
@@ -66,9 +81,9 @@ public function __construct(RequestStack $request_stack, PathMatcher $path_match
6681
/**
6782
* {@inheritdoc}
6883
*/
69-
public static function getSubscribedEvents() {
84+
public static function getSubscribedEvents(): array {
7085
return [
71-
KernelEvents::REQUEST => ['redirectPreferredLanguage'],
86+
KernelEvents::REQUEST => ['redirectPreferredLanguage', self::PRIORITY],
7287
];
7388
}
7489

@@ -78,7 +93,7 @@ public static function getSubscribedEvents() {
7893
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
7994
* The event.
8095
*/
81-
public function redirectPreferredLanguage(RequestEvent $event) {
96+
public function redirectPreferredLanguage(RequestEvent $event): void {
8297
if (!$this->pathMatcher->isFrontPage()) {
8398
return;
8499
}
@@ -97,14 +112,14 @@ public function redirectPreferredLanguage(RequestEvent $event) {
97112
return;
98113
}
99114

100-
// Whether or not preventing redirection when Referer Header is given.
115+
// Whether preventing redirection when Referer Header is given.
101116
$referer_bypass_enabled = (bool) $this->configFactory->get('home_redirect_lang.browser_fallback')->get('enable_referer_bypass');
102117

103118
/** @var \Drupal\Core\Language\Language $current_language */
104119
$current_language = $this->languageManager->getCurrentLanguage();
105120
$http_referer = $this->request->server->get('HTTP_REFERER');
106121
$current_host = $this->request->getHost();
107-
$referer_host = parse_url($http_referer, \PHP_URL_HOST);
122+
$referer_host = parse_url((string) $http_referer, \PHP_URL_HOST);
108123

109124
// Ensure the REFERER is external to disable redirection.
110125
if ($referer_bypass_enabled && !empty($referer_host) && !empty($current_host) && $current_host !== $referer_host) {
@@ -113,7 +128,7 @@ public function redirectPreferredLanguage(RequestEvent $event) {
113128

114129
// When the preferred language cookie exists, then use it instead of the
115130
// browser fallback.
116-
if ($this->request->cookies->has(HomeRedirectLangInterface::COOKIE_PREFERRED_LANGCODE)) {
131+
if ($this->request->cookies->has(HomeRedirectLangInterface::COOKIE_PREFERRED_LANGCODE) && $this->request->cookies->get(HomeRedirectLangInterface::COOKIE_PREFERRED_LANGCODE) !== '') {
117132
return;
118133
}
119134

@@ -126,7 +141,7 @@ public function redirectPreferredLanguage(RequestEvent $event) {
126141
return;
127142
}
128143

129-
// Ensure the stored langcode on the cookie is supported by Drupal.
144+
// Ensure the stored langcode on the browser is supported by Drupal.
130145
/** @var \Drupal\Core\Language\Language|null $destination_language */
131146
$destination_language = $this->languageManager->getLanguage($destination_langcode);
132147

src/EventSubscriber/HomepageCookieLanguageRedirection.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
*/
2323
class HomepageCookieLanguageRedirection implements EventSubscriberInterface {
2424

25+
/**
26+
* The Cookie Redirection must be triggered after the Browser redirection.
27+
*
28+
* The value here must be lower than
29+
* {@HomepageBrowserLanguageRedirection::PRIORITY}.
30+
* This needs to run after \Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest(),
31+
* which has a priority of 32.
32+
* This needs to run after \Drupal\home_redirect_lang\EventSubscriber\HomepageBrowserLanguageRedirection::redirectPreferredLanguage(),
33+
* which has a priority of 31.
34+
*
35+
* @var int
36+
*/
37+
private const PRIORITY = 30;
38+
2539
/**
2640
* Symfony\Component\HttpFoundation\RequestStack definition.
2741
*
@@ -63,9 +77,9 @@ public function __construct(RequestStack $request_stack, PathMatcher $path_match
6377
/**
6478
* {@inheritdoc}
6579
*/
66-
public static function getSubscribedEvents() {
80+
public static function getSubscribedEvents(): array {
6781
return [
68-
KernelEvents::REQUEST => ['redirectPreferredLanguage'],
82+
KernelEvents::REQUEST => ['redirectPreferredLanguage', self::PRIORITY],
6983
];
7084
}
7185

@@ -75,18 +89,18 @@ public static function getSubscribedEvents() {
7589
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
7690
* The event.
7791
*/
78-
public function redirectPreferredLanguage(RequestEvent $event) {
92+
public function redirectPreferredLanguage(RequestEvent $event): void {
7993
if (!$this->pathMatcher->isFrontPage()) {
8094
return;
8195
}
8296

83-
// Whether or not preventing redirection when Referer Header is given.
97+
// Whether preventing redirection when Referer Header is given.
8498
$referer_bypass_enabled = (bool) $this->configFactory->get('home_redirect_lang.cookie')->get('enable_referer_bypass');
8599

86100
$current_language = $this->languageManager->getCurrentLanguage();
87101
$http_referer = $this->request->server->get('HTTP_REFERER');
88102
$current_host = $this->request->getHost();
89-
$referer_host = parse_url($http_referer, \PHP_URL_HOST);
103+
$referer_host = parse_url((string) $http_referer, \PHP_URL_HOST);
90104

91105
// Ensure the REFERER is external to disable redirection.
92106
if ($referer_bypass_enabled && !empty($referer_host) && !empty($current_host) && $current_host !== $referer_host) {

tests/src/Functional/AssertRedirectTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function assertRedirect($path, $expected_destination, $status_code = 301)
4343
*
4444
* @throws \Behat\Mink\Exception\ExpectationException
4545
*/
46-
protected function assertNoRedirect($path, $status_code = 200): void {
46+
protected function assertNoRedirect(string $path, int $status_code = 200): void {
4747
$url = $this->getAbsoluteUrl($path);
4848
$this->getSession()->visit($url);
4949

tests/src/Functional/CookieOverrideBrowserLanguageRedirectionFunctionalTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testCookieMustRedirectOverBrowserPreferredRedirection(string $co
5757
}
5858

5959
/**
60-
* Provides test data for the cookie redirection overrode browser.
60+
* Provides test data for the cookie redirection override browser.
6161
*/
6262
public function providerCookieMustRedirectOverBrowserPreferredRedirection(): iterable {
6363
yield ['en', 'en', 'fr', '/'];

0 commit comments

Comments
 (0)