Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DS-1471] Update redirect to avoid redirecting for cached scripts and styles #73

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openy_system/openy_system.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
26 changes: 26 additions & 0 deletions openy_system/src/EventSubscriber/Routing/RouteSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Drupal\openy_system\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
* Modify core routes to support redirect.
*/
class RouteSubscriber extends RouteSubscriberBase {

/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// See https://www.drupal.org/project/redirect/issues/3373123 .
if ($route = $collection->get('system.js_asset')) {
$route->setDefault('_disable_route_normalizer', TRUE);
}
if ($route = $collection->get('system.css_asset')) {
$route->setDefault('_disable_route_normalizer', TRUE);
}
}

}
19 changes: 15 additions & 4 deletions openy_system/src/EventSubscriber/TermsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
Expand All @@ -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();
Expand Down