Problem/Motivation

I have a contrib module for commerce that I need to pass the order id as a route parameter for the add page route. But EntityController doesn't pass in all the populated route parameters.

Example route:

 *   links = {
 *     "add-page" = "/admin/commerce/orders/{commerce_order}/plan/add",
 *     "add-form" = "/admin/commerce/orders/{commerce_order}/plan/add/{installment_plan_type}",

commerce_order isn't replaced.

Proposed resolution

Inject current_route_match and add the raw route match parameters to the list of params passed to the redirect from add_page to add_form.

Remaining tasks

  • Code it
  • Review it.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Issue fork drupal-2897251

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

heddn created an issue. See original summary.

heddn’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new2.8 KB

Here we go.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Entity/Controller/EntityController.php
@@ -156,7 +167,9 @@ public function addPage($entity_type_id) {
-      return $this->redirect($form_route_name, [$bundle_argument => $bundle_name]);
+      $parameters = $this->routeMatch->getRawParameters()->all();
+      $parameters[$bundle_argument] = $bundle_name;
+      return $this->redirect($form_route_name, $parameters);

Won't this add every parameter as query string, if its not defined on the route?

heddn’s picture

The redirect builds a route and the parameters are route parameters. If there are extra route parameters, they are just ignored. However, if not enough route parameters are provided, then the {commerce_order}, etc doesn't get replaced. So, no it doesn't add every parameter (or any parameter) to a query string. It just route replacements.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new129 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Bhanu951 made their first commit to this issue’s fork.

bhanu951’s picture

Assigned: Unassigned » bhanu951

bhanu951’s picture

Assigned: bhanu951 » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests, +Needs change record

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Did not test

But the new parameter will need to default to NULL and have a trigger_error that it will be required in 11.

Tagging for tests and change record.

bhanu951’s picture

Issue tags: -Needs tests

BC Shim and Test Added.

bhanu951’s picture

Status: Needs work » Needs review
bhanu951’s picture

Issue tags: -Needs change record

Draft CR Created.

smustgrave’s picture

Status: Needs review » Needs work

Small tweak I believe the trigger_error needs to point to the change record.

catch’s picture

Issue tags: +Needs tests

This looks fine, but should we have test coverage for the fixed behaviour?

murilohp made their first commit to this issue’s fork.

murilohp’s picture

Issue tags: -Needs tests
StatusFileSize
new6.71 KB

Hey, I was taking a look here and I think I can help you with the tests part of the fixed behaviour, I've just added a new test entity specific for the add-page/form with multiple parameters, this way I was able to validate the error, here's a test only patch.

murilohp’s picture

Status: Needs work » Needs review

My bad here with the 2897251-test branch, I usually create the test only branch locally and I haven't realized I was on this branch before pushing. Anyway, I would like to remove it, but I don't have the permission, so please ignore it. I have update the correct branch and it's ok to move to NR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reviewing the changes #25

Tests were added
All threads in MR 3333 have been addressed
Change record exists
New constructor has a trigger_error

Thanks!

  • catch committed 373c3da2 on 10.1.x
    Issue #2897251 by murilohp, Bhanu951, heddn, smustgrave:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

The legacy test isn't necessary for constructor bc layers - we only do 'best effort' bc for constructors and that doesn't include test coverage of the deprecations - less code to add then immediately remove in the next release. Added tests for the entity add page look good.

I went ahead and committed the patch to 10.1.x but with the legacy test removed.

bhanu951’s picture

Published CR

Status: Fixed » Closed (fixed)

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