From f4523ffe35163833da7fe95658a1c5266a41de35 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 5 Jun 2024 17:08:29 +0200 Subject: [PATCH 1/2] [DS-1471] Move back fix for redirect to avoid redirecting for cached scripts and styles --- openy_system/openy_system.services.yml | 4 +++ .../src/EventSubscriber/TermsSubscriber.php | 19 +++++++++++--- openy_system/src/Routing/RouteSubscriber.php | 26 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 openy_system/src/Routing/RouteSubscriber.php diff --git a/openy_system/openy_system.services.yml b/openy_system/openy_system.services.yml index f482b01f..6d5d44dc 100644 --- a/openy_system/openy_system.services.yml +++ b/openy_system/openy_system.services.yml @@ -7,3 +7,7 @@ services: arguments: ['@config.factory', '@current_user'] tags: - {name: event_subscriber} + openy_system.route_subscriber: + class: Drupal\openy_system\Routing\RouteSubscriber + tags: + - {name: event_subscriber} diff --git a/openy_system/src/EventSubscriber/TermsSubscriber.php b/openy_system/src/EventSubscriber/TermsSubscriber.php index d751b0e0..f1a5b61e 100644 --- a/openy_system/src/EventSubscriber/TermsSubscriber.php +++ b/openy_system/src/EventSubscriber/TermsSubscriber.php @@ -2,13 +2,13 @@ namespace Drupal\openy_system\EventSubscriber; -use Drupal\Core\Url; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\KernelEvents; /** * Class TermsSubscriber. @@ -28,7 +28,12 @@ class TermsSubscriber implements EventSubscriberInterface { protected $currentUser; /** + * Constructs a new TermsSubscriber event subscriber. * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * * The configuration factory. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current logged user. */ public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) { $this->config = $config_factory->get('openy.terms_and_conditions.schema'); @@ -39,6 +44,12 @@ public function __construct(ConfigFactoryInterface $config_factory, AccountInter * {@inheritdoc} */ public function checkForRedirection(RequestEvent $event) { + $request = clone $event->getRequest(); + // See https://www.drupal.org/project/redirect/issues/3373123 . + if ($request->attributes->get('_disable_route_normalizer')) { + return; + } + $url = Url::fromRoute('openy_system.openy_terms_and_conditions') ->toString(); $request_uri = $event->getRequest()->getRequestUri(); diff --git a/openy_system/src/Routing/RouteSubscriber.php b/openy_system/src/Routing/RouteSubscriber.php new file mode 100644 index 00000000..ab26e436 --- /dev/null +++ b/openy_system/src/Routing/RouteSubscriber.php @@ -0,0 +1,26 @@ +get('system.js_asset')) { + $route->setDefault('_disable_route_normalizer', TRUE); + } + if ($route = $collection->get('system.css_asset')) { + $route->setDefault('_disable_route_normalizer', TRUE); + } + } + +} From 0bbf3b094ce44e0b308089bd12891510346c3f7e Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 5 Jun 2024 18:31:44 +0200 Subject: [PATCH 2/2] [DS-1471] Move RouteSubscriber as a patch to Redirect module --- openy_system/openy_system.services.yml | 4 --- openy_system/src/Routing/RouteSubscriber.php | 26 -------------------- 2 files changed, 30 deletions(-) delete mode 100644 openy_system/src/Routing/RouteSubscriber.php diff --git a/openy_system/openy_system.services.yml b/openy_system/openy_system.services.yml index 6d5d44dc..f482b01f 100644 --- a/openy_system/openy_system.services.yml +++ b/openy_system/openy_system.services.yml @@ -7,7 +7,3 @@ services: arguments: ['@config.factory', '@current_user'] tags: - {name: event_subscriber} - openy_system.route_subscriber: - class: Drupal\openy_system\Routing\RouteSubscriber - tags: - - {name: event_subscriber} diff --git a/openy_system/src/Routing/RouteSubscriber.php b/openy_system/src/Routing/RouteSubscriber.php deleted file mode 100644 index ab26e436..00000000 --- a/openy_system/src/Routing/RouteSubscriber.php +++ /dev/null @@ -1,26 +0,0 @@ -get('system.js_asset')) { - $route->setDefault('_disable_route_normalizer', TRUE); - } - if ($route = $collection->get('system.css_asset')) { - $route->setDefault('_disable_route_normalizer', TRUE); - } - } - -}