Problem/Motivation
In Drupal 7 one could create a view with a page with a path node/%/something, add a node reference field as a contextual filter, give that filter a basic validation criteria and finally give the page a menu as a tab.
This would result in menu tab next to "view" and "edit" only on nodes that fit the validation criteria.
In Drupal 8 the tab is shown on all nodes, but clicking the tab correctly results in a "Page not found" (or access denied if its set to display that).
Steps to reproduce:
- Install the standard profile.
- Add a content entity reference field to the article content type and choose to allow Basic page for reference type.
- Add a view with a page display
- Set the path to node/%node/articles *
- Set the menu to "menu tab"
- Add a contextual filter with the field added in step 2.
- Add validation criteria for the contextual filter and set it to: Content validator and "Basic page" bundle
- Set "page not found" for: Action to take if filter value does not validate
- Create some content and view a Basic page which has some related articles. Verify that the tab is there
- Visit an article content page. - The tab will show up here too
* don't try node/%/articles because it will blow up.
see: #2489940: Views path with menu tab does not validate and results in fatal error
As stated, clicking the tab on article pages, results in a 404 (page not found), since it redirects to "node/[nid]/articles",
which is a non-existing route in this context (it only exists when the nid matches a basic page, and here it is an article).
This is likely caused since menu tabs are created independently of contextual filters and are not aware of
their logic and whether they are valid or not in a given context.
Moreover, while views is altering and adding it's own local tasks,
the local tabs displayed are actually being rendered by the core menu block plugin, which is not aware of the context either.
Proposed resolution
Some thoughts:
Seems that solving this issue would require the menu block plugin to somehow be aware of the context which views defines.
This would also have to somehow account for the various configuration options contextual filters offer, and also handle cache.
Remaining tasks
User interface changes
no
API changes
probably not..
Beta phase evaluation
| Issue category | Bug because it is a functional regression. |
|---|---|
| Issue priority | Normal or Major because it is a functional regression?? |
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | incorrect_tab_on_article_page.png | 83.89 KB | pelegr |
| #5 | correct_tab_on_basic_page.png | 98.84 KB | pelegr |
Comments
Comment #1
bircherComment #2
pelegr commentedWorking with @rcodina on the major issue triage at DrupalCon Barcelona 2015
Comment #3
pelegr commentedComment #4
pelegr commentedComment #5
pelegr commentedComment #6
pelegr commentedComment #7
tim.plunkettDiscussed with @alexpott, @dawehner, @effulgentsia, and @xjm.
The fact that it shows links that will always 404, and since this is a regression from D7, and it has no reasonable or known workaround, this is definitely a major bug.
Comment #8
dawehnerJust by looking into the local task subsystem, I think this would actually even require a change in there. This seems not possible at the moment, to be honest.
Comment #13
megachrizPossible workaround:
_custom_access: '\Drupal\mymodule\Controller\MyController::access'Example access checker for displaying the menu tab only on nodes of type 'article':
Caveats of this workaround:
$nodein the example) MUST exactly match the parameter name configured on the View's path (for example:/node/%node/something).Access check service
Instead of using '_custom_access' as access checker, you can also implement an 'access_check' service. See for an example the RNG module.
From rng.services.yml:
More information about access checking on routes:
https://www.drupal.org/node/2122195
Comment #15
wipeout_dude commentedHi,
I have come across this issue today on a new D8 site.. Is there a fix or workaround for this issue?
Thanks..
Comment #16
tetranz commentedI think this is a duplicate of https://www.drupal.org/project/drupal/issues/2778345
I'd have to revisit it to get my head around it again and update it for 8.7 but I seem to remember that my patch worked.
Comment #17
tetranz commentedThis is definitely a duplicate of 2778345. I've just tested it and it still works although the patch failed to apply. I had to add the lines manually to views.services.yml.
I'll clean it up and hopefully get it in better shape for 8.7.
Comment #18
tetranz commentedI've updated https://www.drupal.org/project/drupal/issues/2778345
I believe that solves this.
Comment #19
twodThis issue is actually older (and already determined to be major as per #7) so let's mark the other one a duplicate. Moving @tetranz's patch here for convenience.
Comment #20
twodNever mind, the other issue is more to the point, sorry about that. Escalating it instead.