Problem/Motivation

What is the way to provide query parameters or other route options for entries in links.menu.yml?

my_module.csv_export:
  title: 'CSV Export'
  enabled: 1
  route_name: view.csv_export.rest_export_1
  options:
    query:
      '_format': csv

Proposed resolution

Document in menu.api.php, specificaly section on @section sec_links how to add options such as query strings.

Remaining tasks

Write a patch.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

heddn created an issue. See original summary.

heddn’s picture

Issue summary: View changes
Issue tags: +Novice

Updated IS. I was missing a query parameter. After I added that, it worked. Looks like this is now a novice task to document in menu.api.php how to pass things beside just route_parameters.

heddn’s picture

Issue summary: View changes
heddn’s picture

Something like this would work, along with an explanation of how to add options.

 * dblog.overview:
 *   title: 'Recent log messages'
 *   parent: system.admin_reports
 *   description: 'View events that have recently been logged.'
 *   route_name: dblog.overview
 *   options:
 *     query:
 *       uid: 1
 *   weight: -1
 * @endcode
dpacassi’s picture

hazong’s picture

Thanks for the proposal, I'm working on it!

hazong’s picture

Attached is the patch with the proposed solution.

hazong’s picture

Status: Active » Needs review
heddn’s picture

Status: Needs review » Reviewed & tested by the community

Great. We have both things needed for these docs updates. A good example, plus some explanatory text of the example.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: enhance_documentation-2998772-7.patch, failed testing. View results

msankhala’s picture

Status: Needs work » Reviewed & tested by the community

Testbot hickup. moving back to RTBC.

Wim Leers’s picture

Title: Route options for links.menu.yml » Document how to specify route options in links.menu.yml
Category: Support request » Task
Issue tags: +Documentation

Thanks for this! Refined issue metadata, otherwise committers may not look at this.

hazong’s picture

So means, I have to look at it again?

heddn’s picture

re #13: no, its that committers don't look at support requests. So moving this to a task is a good idea for this to get committed. No more work now it is in the right queue.

Wim Leers’s picture

Yep! Thanks again, @hazong!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Menu/menu.api.php
@@ -50,6 +53,7 @@
+ * - options: Define additional route options such as e.g. query parameters.

such as e.g seems to be repeating itself. We only need such as. It would be nice to link off to somewhere that describes the full scope of what can go in here.

hazong’s picture

Assigned: Unassigned » hazong
heddn’s picture

I think linking to the url parameter docs would be appropriate.

msankhala’s picture

Assigned: hazong » Unassigned
Status: Needs work » Needs review
FileSize
975 bytes
809 bytes

Here is the updated patch.

heddn’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Menu/menu.api.php
@@ -50,6 +53,9 @@
+ *   https://www.drupal.org/docs/8/api/routing-system/using-parameters-in-routes

This doesn't really talk about URL parameters to a link. Just how to define a route. Perhaps https://www.drupal.org/docs/8/api/routing-system/routing-related-objects... is more better?

msankhala’s picture

This also does not explicitly explains about query parameter neither does Add a menu link doc. I think we can add query option in Add a menu link doc and link it here. Thought?

msankhala’s picture

Any thoughts?

heddn’s picture

kalyansamanta’s picture

Parameter converters are services so you should add an entry to your example.services.yml for your custom ParamConverter:

services:
example.param_converter:
class: Drupal\example\Routing\ParamConverter
tags:
- { name: paramconverter }

Pasqualle’s picture

one more doc page about links.menu.yml, but no mention of the query parameter..
https://www.drupal.org/docs/8/api/menu-api/providing-module-defined-menu...

volkswagenchick’s picture

Issue tags: +fldc19, +sfdug, +dcnj19

Tagging for upcoming contribution days.

msankhala’s picture

volkswagenchick’s picture

Issue tags: +midcamp2019
msankhala’s picture

Status: Needs work » Needs review
FileSize
978 bytes
774 bytes

Thanks @Pasqualle for providing the link to correct doc. Here is the updated patch.

msankhala’s picture

Issue tags: +dcg2019, +DrupalCampGoa2019
heddn’s picture

Status: Needs review » Reviewed & tested by the community

I think this looks good now. All feedback is addressed and the link points to a generally useful docs page.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: document-route-option-menu-link-2998772-29.patch, failed testing. View results

heddn’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: document-route-option-menu-link-2998772-29.patch, failed testing. View results

Mixologic’s picture

Status: Needs work » Reviewed & tested by the community

dispatcher/testbot issue. back to rtbc

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.

larowlan’s picture

Updating issue credits

  • larowlan committed 16afb5c on 8.8.x
    Issue #2998772 by msankhala, hazong, heddn, alexpott: Document how to...

  • larowlan committed eb0b595 on 8.7.x
    Issue #2998772 by msankhala, hazong, heddn, alexpott: Document how to...
larowlan’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 16afb5c and pushed to 8.8.x. Thanks!

c/p as eb0b595e62 to 8.7.x

Status: Fixed » Closed (fixed)

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