Problem/Motivation

It is not obvious, especially to site builders moving to D8 from D7, that under certain circumstances it is necessary to use named route parameters in views paths around entities.

Proposed resolution

Improve the help text that appears under the page path setting in views such that it explains how and when to use named route parameters.

Remaining tasks

none

User interface changes

New help text on the views page path parameter to read (last updated for #27)

This view will be displayed by visiting this path on your site. You may use "%" or named route parameters like "%node" in your URL to represent values that will be used for contextual filters: For example, "node/%node/feed" or "view_path/%". The named route parameters are necessary when used within paths used by entities such as "taxonomy/term/%taxonomy_term" or "user/%user/custom-view"

API changes

none

Data model changes

none - text string update only

Original Issue Summary

An exception is thrown when creating content on a site that includes a view with a menu tab and a path similar to node/%/testing.

Steps to reproduce (see also this exported view):

  1. Clean install of D8
  2. Create a new View named "test", tick the "Create a page" checkbox, change the path to "node/%/test
  3. Click "Save and edit"
  4. Under "Page settings" click the "No menu" link, change "Type" to "Menu tab", add a menu link title, click "Apply"
  5. Under "Advanced" -> "Contextual filters," add a Node ID filter with the default settings, click "Apply"
  6. Click "Save"
  7. Navigate to node/add/article, add some dummy content, click "Save and Publish"

Original report

Posted by laurencefass on June 25, 2015 at 11:22am
twig error creating a views menu tab on content.

following this instruction to create a new tab on a node (as per drupal 7)

View settings:

Page settings
Path: /node/%/customView
Menu: Tab: Custom Node View

the views tabs displays on the node but when i navigate i get the following screen

Error
The website encountered an unexpected error. Please try again later.

...and error log.

Type php
Date Thursday, June 25, 2015 - 10:17
User admin
Location http://rest1.drupal8.com/node/40/customView
Referrer http://rest1.drupal8.com/node/40
Message Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("node") to generate a URL for route "entity.node.devel_load".") in "core/themes/classy/templates/navigation/menu-local-task.html.twig" at line 17. in Twig_Template->displayWithErrorHandling() (line 328 of /home/rest1.drupal8.com/public_html/www/core/vendor/twig/twig/lib/Twig/Template.php).
Severity Error

ps: there is no twig component to select so i placed in under views

CommentFileSizeAuthor
#69 Screenshot 2021-05-26 at 12.46.35.png151.21 KBrachel_norfolk
#67 2511892-67.patch1.5 KBravi.shankar
#65 Screenshot 2020-12-11 at 14.28.03.png156.92 KBrachel_norfolk
#61 2511892-61-MissingMandatoryParametersException-error-on-views.patch1.5 KBbserem
#53 interdiff_47_53.txt1.53 KBbserem
#53 2511892-53-MissingMandatoryParametersException-error-on-views.patch1.45 KBbserem
#3 2511892-view-export.txt4.77 KBmikeker
#8 2511892-7-view-export.txt6.14 KBmikeker
#21 2511892-21-MissingMandatoryParametersException-error-on-views.patch1.34 KBrachel_norfolk
#27 2511892-27-MissingMandatoryParametersException-error-on-views.patch1.42 KBhussainweb
#28 screenshot-2511892-28.png171.85 KBrachel_norfolk
#38 Capture du 2017-07-23 23-54-59.png22.87 KBzenimagine
#38 Capture du 2017-07-24 00-12-02.png8.74 KBzenimagine
#38 Capture du 2017-07-24 00-12-22.png38.33 KBzenimagine
#38 Capture du 2017-07-24 00-12-47.png8.98 KBzenimagine
#38 Capture du 2017-07-24 00-13-12.png35.68 KBzenimagine
#47 2511892_new_message_for_named_route_parameters_updated_text.png23.98 KBbserem
#45 2511892-45-MissingMandatoryParametersException-error-on-views.patch1.51 KBbserem
#47 interdiff_45_47.txt1.05 KBbserem
#45 2511892_new_message_for_named_route_parameters.png24.14 KBbserem
#47 2511892-47-MissingMandatoryParametersException-error-on-views.patch1.5 KBbserem

Issue fork drupal-2511892

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Sounds like a problem of the devel module ...

Syntapse’s picture

does this issue need re-assignment?

mikeker’s picture

FileSize
4.77 KB

does this issue need re-assignment?

No. I'm able to reproduce this with the latest core and without Devel installed. The error is different:

Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("arg_0") to generate a URL for route "view.test.page_1". in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 174 of core\lib\Drupal\Core\Routing\UrlGenerator.php).

(export to reproduce attached).

mikeker’s picture

Title: twig error creating a views menu tab on content » MissingMandatoryParametersException error with a view with menu tab on content
Issue summary: View changes

Updated title and clarified STR in the issue summary.

mikeker’s picture

Issue summary: View changes

Ack! Somehow managed to delete the original report when updating the issue summary. Replaced it from revisions.

Sorry about that...

dawehner’s picture

No. I'm able to reproduce this with the latest core and without Devel installed. The error is different:

MH :(

mikeker’s picture

Priority: Major » Normal

Downgrading priority to normal as the view will render correctly if you use a named route parameter: node/%node/test. The % placeholder is supposed to be used for contextual filters.

However, even if you add a contextual filter you end up with the same exception as above. So some part of this bug remains.

mikeker’s picture

Title: MissingMandatoryParametersException error with a view with menu tab on content » MissingMandatoryParametersException error on views with menu tab and % in the path
Version: 8.0.0-beta11 » 8.0.x-dev
Issue summary: View changes
FileSize
6.14 KB

Updated title, STR, and exported view based on #7.

Chi’s picture

I have got the same error on RC1. Using named parameter as was suggested in #7 resolved the problem.

kevin.dutra’s picture

I can confirm it's still there as of 8.0.1.

tannguyenhn’s picture

#7 worked for me, thanks sir

Syntapse’s picture

...sounds like a simple update of UI help/description needed to close the issue. ?

dawehner’s picture

However, even if you add a contextual filter you end up with the same exception as above. So some part of this bug remains.

So yeah the problem is basically that views would have to allow to name the parameters of generated routes, much like it currently allows to name its routes.

fomenkoandrey’s picture

I have the same error at drupal 8.0.4
I tried to make a tab in the user's profile with his materials.
I use path: "user/%/posts".
Tab and urls like site/user/12/posts works, but i open any profile - i have the error:

Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("arg_0") to generate a URL for route "view.userposts.page_1". in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 177 of core/lib/Drupal/Core/Routing/UrlGenerator.php).

I see this problem occurs with many people.
Is there any way to solve it?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rachel_norfolk’s picture

Having had the same error whilst trying to show a view at /user/%/my-travel-stories, I can confirm that simply changing that path to /user/%user/my-travel-stories fixed the exception and the view displayed correctly. So, yes, we need better documentation on this.

I’m not quite sure how to describe the differences between %, %node, %user etc. Anyone with better understanding?

Andreas Radloff’s picture

Thanks Rachel! Your solution worked for me too, in my case this worked: crm-core/organization/%crm_core_organization/events

ARUN AK’s picture

Hi fomenkoandrey (#14),

Your issue got fixed? Can you please tell me what was the fix? Even I also want to add a tab in user profile page.

Thanks,
ARUN AK

rachel_norfolk’s picture

Arun - note that, when adding a tab to the user profile, you’ll probably want a path in the view of

/user/%user/my-tab

rather than

/user/%/my-tab

Hope that helps.

dawehner’s picture

It would be nice if we could come up with some form of validation for that.

rachel_norfolk’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Active » Needs review
FileSize
1.34 KB

Okay, I believe that the reason people are hitting this error is more down to D8 being different to D7 but people still assuming everything in D8 views is just the same.

As long as a named parameter is used, as described in #7, #16 #17, all is well and works as expected. We just need to better hint at the expectation for a named parameter.

Attached is a patch that adds another example to the already-existing text mentioning named parameters in the views module.

(Interestingly, why was this a patch to views and not views_ui???)

Moved to 8.2.x

ARUN AK’s picture

rachel_norfolk,

I need to add a custom tab in user profile page. I defined my route like below:

mymodule.routing.yml

mymodule.account:
    path: '/user/{user}/custom'
    defaults: 
      _form: '\Drupal\mymodule\Form\MyModuleUserSettingsForm'
      _title: 'Custom Settings'
      user: \d+
    requirements:
      _permission: 'access content'

mymodule.links.task.yml

    mymodule.account:
      title: Mymodule Settings
      route_name: mymodule.account
      base_route: entity.user.canonical

mymodule.links.menu.yml

    mymodule.account:
      title: My module Settings
      parent: entity.user.canonical
      route_name: mymodule.account

Then after clear cache, tab is appearing in profile page. But when I opens the url /user/1/custom getting page not found.

rachel_norfolk’s picture

That’s not something you are doing in views, though, Arun?

WigglyKoala’s picture

I'm not 100% sure the documentation is clear still, the extra example doesn't stop me doing /node/%/test because it mentioned node/%/feed earlier on.

rachel_norfolk’s picture

Status: Needs review » Needs work

Maybe the text could be something more like...

This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed". Sometimes, you may need to specify named route parameters. Examples of named route parameters include "taxonomy/term/%taxonomy_term", "custom_path/%node" and "user/%user/custom-view"

Would that help?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
1.42 KB

The problem, IMHO, is that no one reads until the end of the sentence for the example. When I got this error, I read the comment again but never made it till the end. I then just went to search and found this issue.

Also, it is worth considering that most use cases for placeholders will be to use in paths like user/%/... or node/%/.... It would be worth bringing up the named parameters earlier.

How about something like this?

This view will be displayed by visiting this path on your site. You may use "%" or named route parameters like "%node" in your URL to represent values that will be used for contextual filters: For example, "node/%node/feed" or "view_path/%". The named route parameters are necessary when used within paths used by entities such as "taxonomy/term/%taxonomy_term" or "user/%user/custom-view"

Attaching a patch with above.

rachel_norfolk’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
171.85 KB

Hussainweb in #27 has done a far better job of providing explanatory text here. I think it makes much better sense now and causes me to read the relevant info.

I think it is now a good, simple change. Pity we can’t squeeze it into 8.2!!

Screenshot:
screenshot of patch applied

mikeker’s picture

+1 for #27, much better wording.

Thanks, @hussainweb!

Status: Reviewed & tested by the community » Needs work
hussainweb’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC after random failure.

rachel_norfolk’s picture

Issue tags: +Usability

Placing this in front of the Usability Team as it makes a very useful usability improvement to views.

rachel_norfolk’s picture

Version: 8.3.x-dev » 8.2.x-dev
Issue summary: View changes

I’ve updated the Issue Summary to make this more amenable to committers.

I believe this SHOULD be included in the 8.2 release:

  • It’s a bug (if it’s causing people to do the wrong thing, it’s a bug)
  • It causes no/minimum disruption
  • It is a string, user interface, or render array change
catch’s picture

Status: Reviewed & tested by the community » Needs review

I'm not sure about 'within paths used by entities'.

Isn't the issue that user/%user is an existing path, so we're adding user/%user/foo. But then user/%user/foo isn't "within an entity path".

Maybe something like 'matches an existing entity path. For example adding a view at user/%user/foo when user/%user already exists'.

I also wonder whether we could validate this i.e. look for that exception when validating and show an error if so.

dawehner’s picture

Isn't the issue that user/%user is an existing path, so we're adding user/%user/foo. But then user/%user/foo isn't "within an entity path".

Well the main point is that its an existing path with a certain slug, which has a certain name. On the other hand the really common case is that the slug will have an entity in there, especially in the context of views.

I also wonder whether we could validate this i.e. look for that exception when validating and show an error if so.

We could maybe indeed try to. Good idea.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Lendude’s picture

zenimagine’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

On top of that I believe it would be helpful to allow /node/{node}/example, because well, %node is really not anymore the recommended way. For example the routing system uses {node} under the hood.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

SocialNicheGuru’s picture

I am able to add the path node/%/stuff but I cannot make it a tab.

I understand the issue now
adding % is just for contextual links and adding %someword is for node tabs.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bserem’s picture

The attached patch is based on #27 and applies on Drupal 8.8.x and also tries to emphasize the need for named route parameters.

named route parameters in views

I got this error while working on a contrib module, took me quite some time to figure out that it needed a named route parameter.

vensires’s picture

The patch is fine @bserem! I just tested it on simplytest.me and follows exactly the issue description's proposal. The only change I would suggest is to replace necessary with required which is more common as a word and for a reason I believe.

bserem’s picture

@vensires thanks for the feedback, it actually sounds/looks nicer the way you suggested.

Attached is the new patch, screenshot and interdiff.
named route parameters in views

vensires’s picture

Status: Needs review » Reviewed & tested by the community

Good to go for me.

bserem’s picture

Status: Reviewed & tested by the community » Needs review
bserem’s picture

Status: Needs review » Reviewed & tested by the community

I'm trying to add Vensires in the credit list but apparently I can't.

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs subsystem maintainer review

The help text looks OK to me, but the original report here is describing a situation where just configuring a site via the UI you're able to trigger an exception. I think ideally we'd add some validation here too as well. Tagging for subsystem maintainer review - although we could possibly look at the validation in a separate issue.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
@@ -440,7 +440,11 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
-          '#description' => $this->t('This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed". If needed you can even specify named route parameters like taxonomy/term/%taxonomy_term'),
+          '#description' => $this->t('This view will be displayed by visiting this path on your site.
+            You may use "%" or named route parameters like "%node" in your URL to represent values that
+            will be used for contextual filters: For example, "node/%node/feed" or "view_path/%". The
+            named route parameters are <strong>required</strong> when used within paths used by entities
+            such as "taxonomy/term/%taxonomy_term" or "user/%user/custom-view".'),

We can't break this translatable string into many lines. That makes it impossible for POTX to work this it all needs to be on one line.

bserem’s picture

@alexpott didn't know about that, re-rolled a new patch.

@catch the validation would be tricky because the problem happens if you add a tab with a non-named route parameter. So, the validation should check both the menu settings and the path. It would have to be a validation on the view-level and not these particular settings, because both of them might be correct on their own. It is the combination that triggers the exception.

I will have a look at it, but I do suggest the follow-up issue, as this is gonna be way more complex.

vensires’s picture

Status: Needs review » Reviewed & tested by the community

@catch I also vote for a separate issue on handling the error. Or, at least, making sure that we provide a better DX on why the error occurs (like we did in #2959445: Entity querying config entities does not work, so neither does JSON API collection filtering: provide helpful DX). Validation should be done, in my opinion, in views entity when saved (a constraint maybe?) in order to also catch configuration imports too. But let's not talk too much on this here.

The problem of letting developers discover the same issue again and again (if they find it) is very time-consuming. If it's properly documented in-site just below the field, even simple site builders will be able to resolve it if it occurs to them. Patch is fine again for me, so setting to RTBC; hoping it will land in Drupal core as soon as possible.

catch’s picture

Issue tags: +Needs followup
xjm’s picture

We need that followup filed to go ahead with this change. Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs usability review

Also, I think the correct status is NR for the subsystem maintainer review. I'd suggest reaching out to one of the (other) views maintainers for feedback (@dawhener or @tim.plunkett, in this case).

And a UX review would be good too.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bserem’s picture

Status: Needs review » Reviewed & tested by the community

I am inclined to set this to RTBC as it was in comment #54, for two reasons:
1. I am stumbling upon this every couple of months and I suppose I am not the only one
2. It is stuck in review, waiting for the subsystem maintainer, even though it is a simple wording change.

It applies to 8.9.x and all tests pass.
It doesn't apply to 9.x.x but if this gets a green light we can easily port it.

Lendude’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs subsystem maintainer review, -Needs followup

#2489940: Views path with menu tab does not validate and results in fatal error will do as a 'follow-up' here I feel (it's actually older then this issue).

Since that issue is pretty hard to solve, I think it's a great idea to move ahead with this documentation change first, hopefully helping some people avoid fatal errors.

But in reply to #59, we port the other way around, this needs to go into 9.2.x first and then we backport it to other versions, so we need something that applies to 9.2.x to start with

bserem’s picture

Attached is the patch for drupal 9.2.x (also applies to 9.1.0) as suggested in #60 by Lendude

Patch in #53 stilll applies to drupal 8.9.x and can be used to backport this.

There is no interdiff, since the patch is actually the same.

bserem’s picture

Version: 8.9.x-dev » 9.2.x-dev

bserem’s picture

Following latest updates, a gitlab MR has been created instead of patches.
Hiding patches from the overview.

This MR: https://git.drupalcode.org/project/drupal/-/merge_requests/125 is the same as #61

rachel_norfolk’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
156.92 KB

Okay -

1. I have used the preview on tugboat to check that the correct text is appearing when building a view, as below:

Screenshot of views dialog showing the updated text

2. We have already confirmed that we are happy with the updated language.

I think it is time to mark this as RTBC!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
@@ -437,7 +437,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+          '#description' => $this->t('This view will be displayed by visiting this path on your site. You may use "%" or named route parameters like "%node" in your URL to represent values that will be used for contextual filters: For example, "node/%node/feed" or "view_path/%". The named route parameters are <strong>required</strong> when used within paths used by entities such as "taxonomy/term/%taxonomy_term" or "user/%user/custom-view".'),

I still agree with @catch that the within paths used by entities feels tricky. I think we can be more explicit here. For example we could say...

This view will be displayed by visiting this path on your site. You may use "%" or named route parameters like "%node" in your URL to represent values that will be used for contextual filters: For example, "node/%node/feed" or "view_path/%". Named route parameters are required when this path matches an existing path. For example, paths such as "taxonomy/term/%taxonomy_term" or "user/%user/custom-view".

The one issue with the above is that it only covers the partial matching of user/%user and user/%user/custom-view - but I think that this is okay because we have the example. Maybe someone else has an idea about how to make this even clearer but given the point of this issue is to improve the text I think it is worth refining until we have something that someone new to Drupal can think "yep I get that".

ravi.shankar’s picture

Status: Needs work » Needs review
FileSize
1.5 KB

Made changes as per comment #66.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rachel_norfolk’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
151.21 KB

Thanks Alex and Ravi for the updates to the language. It is a lot better now.

Confirming that the latest patch does indeed reflect the language suggested in #66

screenshot showing language as proposed in #66

Setting back to RTBC

larowlan’s picture

Saving issue credits and updating tags

  • larowlan committed b796e37 on 9.3.x
    Issue #2511892 by bserem, rachel_norfolk, hussainweb, ravi.shankar,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +String change in 9.3.0

Committed b796e37 and pushed to 9.3.x. Thanks!

I didn't backport this to 9.2.x because there's a string change, and that would break existing translations. We only do that in minor versions. Tagging as such.

Status: Fixed » Closed (fixed)

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

iamfredrik’s picture

The patch doesn't seem to work with commerce products. I get the following errors:

/product/%/mytab
Some mandatory parameters are missing ("arg_0") to generate a URL for route "view.myview.page_1"

/product/%product/mytab
Some mandatory parameters are missing ("product") to generate a URL for route "view.myview.page_1"

vensires’s picture

@iamfredrik you should check what the entity declares as route in its annotation. Check Product.php and you will see that the canonical URL is /product/{commerce_product}. As a result, you should use /product/%commerce_product/mytab.

dbroll’s picture

Does anyone know what was actually added to core to resolve this? I'm on a d8 site with commerce, so looking to backport this functionality if i need to. I have setup a view with url /products/%commerce_product/variations-bulk and am getting this error:

TypeError: Argument 1 passed to Drupal\Core\Entity\EntityRepository::getTranslationFromContext() must implement interface Drupal\Core\Entity\EntityInterface, string given, called in /modules/contrib/commerce/modules/product/src/ProductVariationListBuilder.php on line 73 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 99 of core/lib/Drupal/Core/Entity/EntityRepository.php).

As views is passing a string for "product_id" rather then the product object. Any ideas how to fix?

bserem’s picture

Yeah, we improved the help message so that it is clear for users what to do.
See: https://git.drupalcode.org/project/drupal/-/commit/b796e3779b21e1f62f9e5...

dbroll’s picture

@bserem thanks, per the description I think i'm using the correct syntax for my url (/products/%commerce_product/variations-bulk) but am still getting an error. Is that a commerce issue? Or a views/core issue?