Forward a destination query parameter on entity add pages

Created on 29 December 2021, almost 3 years ago
Updated 4 April 2023, over 1 year ago

Problem/Motivation

\Drupal\Core\Entity\Controller\EntityController::addPage() provides a generic add page for entities, with a link to the add form for each bundle. When editing or deleting entities from the entity collection, the list builder adds destination query parameters to the respective links, so that the user is returned to the collection after the operation. This would be a nice, feature for adding an entity, as well. Currently, however, the destination query parameter does not make sense for entities with bundles as the destination will get lost on the add page. (And in fact it leads to problems if there is only one bundle, see #3181860: Collection local action should not have a destination for the add *page* (vs. form) ).

Steps to reproduce

-

Proposed resolution

In \Drupal\Core\Entity\Controller\EntityController::addPage() check if the request contains a destination query parameter and if so, add it to the add links (and the redirect in case of a single bundle).

See https://git.drupalcode.org/project/entity/-/merge_requests/8 for an equivalent implemenation in the Entity API module.

Remaining tasks

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

-

Feature request
Status

Needs work

Version

10.0

Component
Entity 

Last updated about 20 hours ago

Created by

🇩🇪Germany tstoeckler Essen, Germany

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    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.

    This will need test coverage.
    Left a comment but think we should make the new parameter default to NULL for backwards compatibility. With a trigger_error it will be required in D11.

  • 🇦🇹Austria mvonfrie

    Please make this more generic and pass through all query parameters. While destination needs special handling, other query parameters could just be passed through. Or if that is too open maybe trigger an event to retrieve the query parameters to pass for a specific request.

    In my use case I need a query parameter "owner" in order to set the owner of the new entity to a defined user passed via query parameter (and hiding the author selection UI) instead of the current user creating the new entity. The entity is a commerce product which should be owned by the "seller" user (which has an "add product" action on its profile, accessible to the seller user and all shop managers + admins) and not the "shop manager" or admin user creating the product. Without this issue being generic my only option would be to add separate local actions per product bundle.

Production build 0.71.5 2024