Provide an optional destination parameter for local actions

Created on 17 November 2011, almost 13 years ago
Updated 6 December 2023, 9 months ago

Problem/Motivation

Currently local actions do not provide a destination which results in an inconsistent UX because users expect to return to the page where they clicked the button.

Steps to reproduce:

  1. Sign in as an administrator
  2. Go to admin/people
  3. Click the 'Add user' local action
  4. Fill out the form to add a new user.
  5. You get 'stuck' on the Add user page, when most people would have wanted to return to the People listing.

Proposed resolution

Provide a local action option parameter so the user is 'returned' to the page from where the click on the action link originated.

Remaining tasks

  • Expand documentation in menu.api.php
  • Expand functionality allowing to set a destination? (see #36 point 5)
  • Review
  • Create change record

User interface changes

When the option is provided in a specific local action *.links.action.yml, the user who clicks the action will be redirected to the destination parameter path. @alexpott in comment #36.5 proposes that the destination route could be specified in the yml entry.

API changes

There is a new option 'add_destination' available for local action plugins. @alexpott in comment #36.5 proposes that option should have the form: destination: some.route_name allowing developers to specify any route for the destination.

Data model changes

None.

Release notes snippet

Needs change record.

Feature request
Status

Needs work

Version

11.0 🔥

Component
Menu system 

Last updated 1 day ago

Created by

🇺🇸United States Dave Reid Nebraska 🇺🇸

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

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

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • 🇮🇳India sahil.goyal

    Trying to fix CCF errors, Facing some difficulties to create interdiff, So here i updating the patch alone.

  • 🇮🇳India Nikhil_110

    Trying to fix CCF errors and add interdiff..

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇫🇷France andypost
    +++ b/core/lib/Drupal/Core/Menu/LocalActionDefault.php
    @@ -37,11 +45,18 @@ class LocalActionDefault extends PluginBase implements LocalActionInterface, Con
    +      @trigger_error('The redirect.destination service must be passed to LocalActionDefault::__construct(), it is required before Drupal 10.0.0.', E_USER_DEPRECATED);
    
    +++ b/core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php
    @@ -10,6 +10,10 @@
    + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use the
    
    @@ -35,6 +39,7 @@ class MenuLinkAdd extends LocalActionDefault {
    +    @trigger_error("\Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use the 'add_destination: true' option in declaration of action links.", E_USER_DEPRECATED);
    

    deprecated in 10.1.0, removed from 11.0.0

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India mrinalini9 New Delhi

    Updated patch #51 by addressing #53, please review it.

    Thanks & Regards,
    Mrinalini

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Reviewing for the 'Needs framework manager review' tag.

    I would implement this differently

    • Firstly, copy MenuLinkAdd to Drupal\Core\Menu\LocalActionWithRedirect or similar
    • Secondly, gut MenuLinkAdd and have it extend the new class, and retain the deprecation error
    • Then instead of adding a new property to the yaml, for the links that need this, just add class: Drupal\Core\Menu\LocalActionWithRedirect

    This avoids needing to add a new property and just uses the plugin system we already have.

    Thoughts?

  • heddn Nicaragua

    +1 to the idea in #55.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Like the idea of #55 also.

    Moving to NW for those changes. Also issue summary should be updated to match new proposal.

  • 🇧🇪Belgium gorkagr

    Hi!

    I like the idea of #55 as using a class called LocalActionWithRedirect is more intuitive than MenuLinkAdd.

    On the other hand, in the documentation (a bit outdated), it is written in both menu.links and local.tasks examples of how to use the 'options' within the yml, and:

      options:
        query:
          destination: '/path/to/route'
    

    can be defined if we need a destination different than the same route (which is added by default when using the class).

    But nothing is documented in the links.actions page

    Best

  • 🇦🇺Australia sime Canberra

    Yes, per #59 if you do this code below then the current implementation of MenuLinkAdd will clobber this.

    /**
     * Implements hook_menu_local_actions_alter(),
     */
    function MYMODULE_menu_local_actions_alter(&$local_actions) {
      if (isset($local_actions['foo.bar'])) {
        $local_actions['foo.bar']['options']['query']['destination'] = '/cheese';
      }
    }
Production build 0.71.5 2024