Skip to content
Snippets Groups Projects

Move callback classRemove outside of the loop

2 files
+ 36
3
Compare changes
  • Side-by-side
  • Inline
Files
2
  • 386c3292
    Issue #3120301 by alexpott, zestagio, Wim Leers: RoutePreloader: prevent... · 386c3292
    catch authored
    Issue #3120301 by alexpott, zestagio, Wim Leers: RoutePreloader: prevent preloading of routes generated by JSON:API
@@ -8,6 +8,7 @@
@@ -8,6 +8,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\KernelEvents;
 
use Symfony\Component\Routing\Route;
/**
/**
* Defines a class which preloads non-admin routes.
* Defines a class which preloads non-admin routes.
@@ -98,7 +99,7 @@ public function onRequest(KernelEvent $event) {
@@ -98,7 +99,7 @@ public function onRequest(KernelEvent $event) {
public function onAlterRoutes(RouteBuildEvent $event) {
public function onAlterRoutes(RouteBuildEvent $event) {
$collection = $event->getRouteCollection();
$collection = $event->getRouteCollection();
foreach ($collection->all() as $name => $route) {
foreach ($collection->all() as $name => $route) {
if (strpos($route->getPath(), '/admin/') !== 0 && $route->getPath() != '/admin') {
if (strpos($route->getPath(), '/admin/') !== 0 && $route->getPath() != '/admin' && static::isGetAndHtmlRoute($route)) {
$this->nonAdminRoutesOnRebuild[] = $name;
$this->nonAdminRoutesOnRebuild[] = $name;
}
}
}
}
@@ -126,4 +127,21 @@ public static function getSubscribedEvents() {
@@ -126,4 +127,21 @@ public static function getSubscribedEvents() {
return $events;
return $events;
}
}
 
/**
 
* Determines whether the given route is a GET and HTML route.
 
*
 
* @param \Symfony\Component\Routing\Route $route
 
* The route to analyze.
 
*
 
* @return bool
 
* TRUE if GET is a valid method and HTML is a valid format for this route.
 
*/
 
protected static function isGetAndHtmlRoute(Route $route) {
 
$methods = $route->getMethods() ?: ['GET'];
 
// If a route has no explicit format, then HTML is valid.
 
// @see \Drupal\Core\Routing\RequestFormatRouteFilter::getAvailableFormats()
 
$format = $route->hasRequirement('_format') ? explode('|', $route->getRequirement('_format')) : ['html'];
 
return in_array('GET', $methods, TRUE) && in_array('html', $format, TRUE);
 
}
 
}
}
Loading