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].

Issue fork gutenberg-3607961

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vegardjo created an issue. See original summary.

vegardjo’s picture

Didn'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...

vegardjo’s picture

Status: Active » Needs review
jclopez’s picture

Thanks for the patch!

trebormc’s picture

works fine for me

lizuka’s picture

Version: 4.0.x-dev » 3.0.6
StatusFileSize
new7.02 KB

Confirming 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:77

Cause: 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?

sivakarthik229’s picture

StatusFileSize
new5.29 KB

Adding 8.x-2.x compatibility version patch.

joelpittet’s picture

Where 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.

neclimdul’s picture

I 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 🤷.

neclimdul’s picture

anybody’s picture

Status: Needs review » Needs work

Still NW to turn the patches into MRs. Confirming this issue and the patches to solve it.