Tip: Use MenuLinkAdd local action to add a return destination

Adding a ?destination=/path/to/redirect argument to a link makes the page's submit button redirect to the given path.

An admin page or dashboard may need to have local actions that go to forms provided by other modules. This technique is a quick way to have those actions return to the last dashboard tab when the task is done.

MenuLinkAdd is a plugin in core that extends LocalTaskDefault. It's used to redirect back to the menu config after saving a menu link. But it does it in a generic way that will just redirect back to the page you started from.

To use it, just specify the class in your local action.

module.payment.add_form:
  route_name: entity.payment.add_form
  title: 'Add payment'
  class: \Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd
  appears_on:
    - entity.order.payment
Tags
Menu