I want to display custom content for the user profile page instead of the entity view so I am altering the entity.user.canonical route and I am setting a custom controller and title compared to the entity view and page callback that is set by the UserRouteProvider. I am leaving the requirements athey are since I don't need to change anything regarding the permissions.
Strangely though I am still getting Access denied after I flush the cache. The code that I am using in my event subscriber that is run on the RoutingEvents::ALTER event is:
$collection = $event->getRouteCollection();
$route = $collection->get('entity.user.canonical');
$route->setDefaults(array(
'_controller' => '\Drupal\mymodule\Controller\UserController::profilePage',
'_title' => 'Profile'
));
If I will use setDefault('_controller'...) instead of setDefaults() method it will work since I think the _controller has more priority over _entity_view but the _title does not have priority over _title_callback. So this is not a viable solution.
Any idea what the issue with that access might be? Does the _entity_access requirement require the _entity_view to be used instead of the controller? Should the presence of the entity in the url be sufficient?