Forward a destination query parameter on entity add pages

Created on 29 December 2021, almost 3 years ago
Updated 6 February 2023, almost 2 years 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 17 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

Merge Requests

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.

  • 🇩🇪Germany tstoeckler Essen, Germany

    Re #4: Thanks for the review! Added a draft change notice and the in-code deprecation. The merge request already adds a bunch of assertions to EntityAddUITest so what test coverage are you looking for exactly?

    Re #5: I understand the use-case totally, but given that it's already hard enough to find support for this very targeted issue I don't believe broadening the scope is wise at this point. Feel free to post a separate MR (here or in another issue) for your use-case but I will continue with the current approach for now, sorry.

  • Pipeline finished with Canceled
    29 days ago
    Total: 276s
    #351674
  • Pipeline finished with Canceled
    29 days ago
    Total: 172s
    #351678
  • Pipeline finished with Failed
    29 days ago
    Total: 1667s
    #351686
  • Pipeline finished with Success
    29 days ago
    Total: 523s
    #352066
Production build 0.71.5 2024