Problem/Motivation
Receiving an intermittent error on a site:Uncaught PHP Exception Drupal\Component\Plugin\Exception\PluginNotFoundException: "The "views_view:view.comment.page_published" plugin does not exist. Valid plugin IDs for Drupal\Core\Menu\LocalTaskManager are ...
The error can be fixed with a cache rebuild but it will eventually come back. The view it is looking for is a view with a page display which overrides the existing route for 'comment.admin'. This route is a local task on the 'content.admin' route and the error is thrown intermittently when we navigate to any local task on 'content.admin'.
Based on the code in Drupal\views\EventSubscriber\RouteSubscriber::alterRoutes, and Drupal\views\Plugin\views\display\PathPluginBase::alterRoutes, I don't believe the view should be an existing local task. It should only be looking for 'comment.admin'.
In PathPluginBase::collectRoutes the view display is added with route name 'view.comment.page_published' Later at RouteSubscriber::alterRoutes when views alters to override existing routes, it removes it as 'views.comment.page_published' but this does not exist. I think they should have the same name. If I change them to match then Drupal stops looking for the view route which is what I would expect.
Then, we have webform modules installed on our site and the local tasks get loaded up on webform's implementation of `hook_menu_links_discovered_alter` if you also have `admin_toolbar_tools` installed. This happens before views has set the altered list of routes in state variable 'views.view_route_names' and so views that are supposed to be overriding an existing route, get put into the local tasks using the view route instead of the overridden route. Views sets this data on event 'routing.route_finished'. If you don't load the local tasks before views sets it then everything seems to work fine, even though the route old view route isn't properly removed.
This is similar to https://www.drupal.org/project/drupal/issues/3164711 and https://www.drupal.org/project/brightcove/issues/3270406.
Steps to reproduce
- Add a page view that overrides an existing route which is a local task on another route (e.g. comment.admin is local task of content.admin).
- Load up local tasks during `hook_menu_links_discovered_alter`:\Drupal::service('plugin.manager.menu.local_task')->getDefinitions();
which will put the views routes into the local task list instead of the route they are overriding.
- An intermittent issue usually happens at some point after cim/updb and cache clear when loading up the route.
- No other clear steps to reproduce at this point.
Short term resolution
- Cache clear: drush cr seems to resolve the issue until it surfaces again.
Long term resolution
- Fix name of route removed from the collection, run views subscriber to routing.route_finished before hook_menu_links_discovered_alter is run.