- Issue created by @gouthamraon
- 🇫🇷France gilbertdelyon
@gouthamraon
Same issue on my side.
The site is 100% private.
I have a custom module that redirects unauthenticated users to login page.It works like a charm when Aggregate CSS is not active
It doesn't work when Aggregate CSS is active (css is not loaded because wrong mime type, same error as yours)Did you find a way in the meantime?
- 🇫🇷France gilbertdelyon
I found a way. may be not a good practice but it works!
First attempt:
In mymodule/src/EventSubscriber/Mysbsciber.php$loginurl = Url::fromRoute('user.login')->toString(); $event->setResponse(new RedirectResponse($loginurl, 301));
It works only when aggregate CSS is disabled
Second attempt:
In mymodule/src/EventSubscriber/Mysbsciber.php$loginurl = Url::fromRoute('user.login')->toString(); header('Location: '.$loginurl) exit;
It works only when aggregate CSS is disabled
Third attempt:
In mymodule/src/EventSubscriber/Mysbsciber.php$loginurl = Url::fromRoute('user.login')->toString(); ?> <script type="text/javascript"> window.location.rel="noopener" target="_blank" href= "<?=$loginurl?>";> </script> <?php
It works in any case (css aggregate active or inactive)
- 🇮🇳India Supreetam09 Kolkata
I don't think this issue is coming from advagg module. We are also facing this issue and trying to figure out whats causing this but we are not using this module. Maybe try to uninstall this module once and check if the issue still persists to confirm if the issue is from this module.
- 🇫🇷France gilbertdelyon
Unfortunately I couln't find the reason.
Our custom module is redirecting anonymous users to login page by way of a controller (based on this example: https://drupal.stackexchange.com/a/223109)
Redirection works perfectly but style is not loaded when "aggregate css" is selected.So we have deleted the controller and now we use a simple hook (https://drupal.stackexchange.com/a/295593) may be not the best practice but now it works!
- 🇷🇴Romania radubutco
@gilbertdelyon Probably because you alter also the response for the css request which gets the aggregated files.
You can try something like this in your EventSubscriberif (php_sapi_name() == 'cli' || strpos($event->getRequest()->getRequestUri(), 'sites') !== FALSE) { return; }
- 🇫🇷France gilbertdelyon
Thank you, I will try
BTW: As explained in #6 , since I had this issue I now redirect by way of a hook instead of a controller (and it works!).
If the suggestion in #7 works, I worry If I should go back to a controller.
Which wy is the most recommended: hook or controller? - 🇫🇷France gilbertdelyon
@radubutco
Thank you for your precious help #7. It works!
- Status changed to Closed: works as designed
9 months ago 4:14pm 13 February 2024 - 🇮🇳India Supreetam09 Kolkata
In that case, this issue can be closed right?
Closing this. Reopen if you feel otherwise.