Problem/Motivation
Hi, when updating to Drupal 11.4 I get:
Fatal error: Uncaught TypeError: Drupal\Core\Routing\StaticRouteDiscoveryBase::createRoute(): Argument #7 ($methods) must be of type array, string given, called in /var/www/html/web/core/lib/Drupal/Core/Routing/YamlRouteDiscovery.php on line 83 and defined in /var/www/html/web/core/lib/Drupal/Core/Routing/StaticRouteDiscoveryBase.php:77
This is because methods in the routing file are defines as strings, like 'GET', but should be arrays, like [GET].
Comments
Comment #2
vegardjo commentedDidn't really get why a MR from this included a lot of other stuff, but likely as it is forked from the dev branch. This should however be fix in commit: https://git.drupalcode.org/issue/gutenberg-3607961/-/commit/904ec41baeba...
..and testing patch should be possible with https://git.drupalcode.org/issue/gutenberg-3607961/-/commit/904ec41baeba...
Comment #3
vegardjo commentedComment #4
jclopez commentedThanks for the patch!
Comment #5
trebormcworks fine for me
Comment #6
lizuka commentedConfirming this also affects the 3.0.x branch, not just 4.0.x-dev.
Environment:
Gutenberg 3.0.6
Drupal core 11.4
PHP 8.4
Error (on any cache rebuild, e.g. drush cr):
PHP Fatal error: Uncaught TypeError: Drupal\Core\Routing\StaticRouteDiscoveryBase::createRoute(): Argument #7 ($methods) must be of type array, string given, called in .../core/lib/Drupal/Core/Routing/YamlRouteDiscovery.php on line 83 and defined in .../core/lib/Drupal/Core/Routing/StaticRouteDiscoveryBase.php:77Cause: as of Drupal 11.4, StaticRouteDiscoveryBase::createRoute() requires $methods to be an array. In gutenberg.routing.yml the HTTP methods are declared as strings (methods: 'GET'), which now throws.
Fix: wrap each declaration in an array (methods: 'GET' → methods: ['GET']). Same change as the 4.0.x MR, applied to 3.0.x — it resolves the fatal error and drush cr completes normally.
Attaching a patch against 3.0.6. Could this be backported to the 3.0.x branch?
Comment #7
sivakarthik229 commentedAdding 8.x-2.x compatibility version patch.
Comment #8
joelpittetWhere the problem was introduced #3311365: Use PHP attributes for route discovery
Likely not the only one affected by the inadvertent BC bug, a hot fix for casting the value to an array would be my recommendation in an upstream fix.
There’s good precedent: issue #3358402: [regression] route defaults are now automatically route parameters was a similar case where a strict-typing change broke contrib modules.
This patch should be in the MR, and be committed as well here as well since string was never a Drupal core documented https://www.drupal.org/docs/drupal-apis/routing-system/structure-of-routes I looked back through the revisions to 2020 and it’s been an array for a while, just happened Drupal was less strict before 11.4 and syncing used to support both.
Comment #9
neclimdulI feel pretty strongly core shouldn't break contrib like this so opened the core issue https://www.drupal.org/project/drupal/issues/3608776
Maybe it wasn't documented, but Symfony's routing _was_ the previous interface so I think core should preserve that interface and if it is going to change it needs to be deprecated. It is a nice shortcut so I'd keep it but 🤷.
Comment #10
neclimdulComment #11
anybodyStill NW to turn the patches into MRs. Confirming this issue and the patches to solve it.