0

I have the following RouteSubscriber in a custom module:

namespace Drupal\frilaering_access\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

class RouteSubscriber extends RouteSubscriberBase {

  protected function alterRoutes(RouteCollection $collection) {

    if ($route = $collection->get('user.logout')) {
      $route->setRequirement('_access', 'FALSE');
    }

    //THIS ONE STILL APPEARS IN THE MENU FOR SOME REASON
    if ($route = $collection->get('entity.user.edit_form')) {
      $route->setRequirement('_access', 'FALSE');
    }

    if ($route = $collection->get('entity.user.canonical')) {
      $route->setRequirement('_access', 'FALSE');
    }
  }
}

And although access is denied the link to the user edit page is still visible in the menu. The other 2 menu items are hidden as they should be.

Any idea why this is not working for the user.edit_form?

EDIT - here is my subscriber:

services:
  frilaering_access.route_subscriber:
    class: Drupal\frilaering_access\Routing\RouteSubscriber
    tags:
      - { name: event_subscriber }
2
  • Can you show us the route definition in your routing.yml?
    – pixel5
    Jul 19, 2022 at 15:31
  • Thanks - added now. But as I say, the alters are working - the requirements are set. But the menu item for user/edit stays visible
    – Morten
    Jul 19, 2022 at 16:23

1 Answer 1

0

Sorry, I just discovered that the "Edit user" link is provided by the module "User current paths", so the solution was to use the route "user_current_paths.edit_redirect".

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.