Hello!

My bug can be reproduced with the following steps:

1. Create a module with a custom route that has two parameters:

example.routing_example:
  path: '/example-page/{id1}/{id2}'
  defaults:
    _title: 'Routing Example'
    _controller: '\Drupal\<module_name>\Controller\ControllerClass::action'
  requirements:
    _permission: 'access content'

2. Create Custom menu links (menu_link_content) that follow the above rule
3. Enable indexing on the menu where these menu links are added
4. Generate sitemap

On generation we get a 500 error, because the route parameters do not match and id1 is empty.

The snippet of code responsible for this is in Batch.php on line 176

  $route_parameters = array(key($route_parameters) => $route_parameters[key($route_parameters)]);

This forces the route parameters to contain only the last parameter in the route.

Was there a specific reason for forcing this behaviour? Because after unserializing, the $route_parameters array should be in the correct format.

I can upload a patch that resolves this, but I just wanted to make sure that I'm aware of all the implications.

Thank you!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

benelori created an issue. See original summary.

gbyte’s picture

Hi benelori, to be honest, I'm not quite sure anymore. Please test with a variety of menu links and submit a patch; I'll be happy to double check and commit. This is another thing we would actually need tests for...

benelori’s picture

Status: Active » Needs review
FileSize
2.36 KB

I've uploaded a patch for the issue and tested with multiple parameters (1, 2 and 3) for links generated as menu_link_content entities.

gbyte’s picture

Status: Needs review » Active

Thanks benelori, I'm going to incorporate your findings into some refactoring the batch class badly needs. I'm going to take care of this next week as soon as I find the time.

rosinegrean’s picture

Status: Active » Needs review
FileSize
549 bytes
2.44 KB

Hey,

I saw a small issue in the fix from the patch which made the logs flood with the same notice.
Thanks,

  • gbyte.co committed fe0d839 on 8.x-2.x authored by benelori
    Issue #2700981 by prics, benelori: Cannot generate routes that have more...
gbyte’s picture

Title: Cannot generate routes that have more than parameter » Cannot generate routes that have more than one parameter
Status: Needs review » Fixed

Thanks benelori, sorry it took a bit longer. I didn't use your patch, but attributed the authorship to you, as you fixed the bug. Please test this in 8.x-2.x.

gbyte’s picture

Version: 8.x-2.2 » 8.x-2.x-dev
benelori’s picture

Sure no problem!

I tested against 8.0.0 and 8.1.0 and works like a charm, plus the warnings that @prics mentioned are gone as well.

Thanks!

Status: Fixed » Closed (fixed)

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