diff --git a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php index b782d9af627..beb988f6ebe 100644 --- a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php +++ b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php @@ -25,7 +25,7 @@ public function filter(RouteCollection $collection, Request $request) { $format = $request->getContentType(); foreach ($collection as $name => $route) { - $supported_formats = array_filter(explode('|', $route->getRequirement('_content_type_format'))); + $supported_formats = array_filter(explode('|', $route->getRequirement('_content_type_format') ?? '')); if (empty($supported_formats)) { // No restriction on the route, so we move the route to the end of the // collection by re-adding it. That way generic routes sink down in the diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index fb59cf562f9..b3733e4ec87 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -383,10 +383,11 @@ public function collectRoutes(RouteCollection $collection) { * TRUE, when the view should override the given route. */ protected function overrideApplies($view_path, Route $view_route, Route $route) { - $route_formats = explode('|', $route->getRequirement('_format')); - $view_route_formats = explode('|', $view_route->getRequirement('_format')); + $route_has_format = $route->hasRequirement('_format'); + $route_formats = $route_has_format ? explode('|', $route->getRequirement('_format')) : []; + $view_route_formats = $view_route->hasRequirement('_format') ? explode('|', $view_route->getRequirement('_format')) : []; return $this->overrideAppliesPathAndMethod($view_path, $view_route, $route) - && (!$route->hasRequirement('_format') || array_intersect($route_formats, $view_route_formats) != []); + && (!$route_has_format || array_intersect($route_formats, $view_route_formats) != []); } /** diff --git a/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php b/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php index a90d4f4607c..ee4c013b69e 100644 --- a/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php +++ b/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php @@ -24,7 +24,7 @@ public function filter(RouteCollection $collection, Request $request) { foreach ($collection as $name => $route) { // _format could be a |-delimited list of supported formats. - $supported_formats = array_filter(explode('|', $route->getRequirement('_format'))); + $supported_formats = array_filter(explode('|', $route->getRequirement('_format') ?? '')); if (empty($supported_formats)) { // No format restriction on the route, so it always matches. Move it to