#2917331: Decouple from Symfony CMF changed the return value of \Drupal\Core\Routing\RouteProvider::getAllRoutes, it no longer returns an iterable \Symfony\Cmf\Component\Routing\PagedRouteCollection object, now returns an array. This will break BC.

Previously the interface claimed the method returned an array, and there was little testing for this method, which resulted in this code change.

Example of a break with \iterator_to_array(): https://3v4l.org/PGM6Z

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dpi created an issue. See original summary.

catch’s picture

Is this breaking a contrib module? Or otherwise how did you spot the change?

We currently don't have a clear policy for when implementations fail to match interfaces (i.e. whether changing the interface or the implementation should be considered the bc break). The description and type hint in the interface contradict each other: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Routing%2...

If we want to change the interface and keep the older implementation, then we should just go ahead and return an iterator again. Wrapping the array in ArrayObject is easy but does PHP have anything lighter these days?

dpi’s picture

It broke Entity Route Context, until things were reworked.

catch’s picture

Status: Active » Needs review
FileSize
635 bytes
1.09 KB

afaict ArrayObject is still the simplest option here. Here's a patch with test coverage.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks nice and simple :)

The last submitted patch, 4: 3158708-test-only.patch, failed testing. View results

andypost’s picture

+1 rtbc

dww’s picture

RouteProviderInterface still says this:

   * @return \Symfony\Component\Routing\Route[]
   *   An iterator of routes keyed by route name.

I thought [] meant an array, not an iterator. How do you tell the difference in PHPDoc comments?

Thanks,
-Derek

jibran’s picture

Do we want to add BC warning here?

larowlan’s picture

Do we want to add BC warning here?

I don't think we do, because this was only in 9.1

  • larowlan committed c6aa9bc on 9.1.x
    Issue #3158708 by catch: RouteProvider::getAllRoutes no longer returns...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed c6aa9bc and pushed to 9.1.x. Thanks!

Re #8 I don't think we're consistent

E.g. We have \Drupal\migrate\Plugin\MigrateIdMapInterface::getMessages, \Drupal\migrate\Plugin\MigrateIdMapInterface::getMessageIterator amongst others.

As this is a critical and we don't want it to ship in a tagged release, committed as is. Can we get a follow-up for #8?

larowlan’s picture

Issue tags: +Bug Smash Initiative

Tagging as this was flagged in the #bugsmash channel which led me here

dpi’s picture

🕺

dww’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.