0

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?

1 Answer 1

0

Can't be sure as you haven't posted your controller, but my guess would be that you are not type hinting the argument there as UserInterface $user, so it doesn't get upcasted. That is required for _entity_access to work

1
  • OMG, you are right. I though the entity has been processed already. My controller was just return array() for testing without any arguments. Thanks.
    – user21641
    May 6, 2015 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.