I installed Forum module.
So, I have 'Forums' link in 'Tools' menu corresponding to the path /forum defined in forum.routing.yml in which access is defined by _permission: 'access content'.
In my site, anonymous users are allowed to "View published content", so they can see the 'Forum' link.
I don't want anonymous users to be able to see forums and, therefore, the forum topics.
I thought to override the _permission of forum.routing.yml but I don't know how to do that?
How can I do that?

Or is there another solution?

3 Answers 3


You can change the permission associated with a route doing what Altering existing routes and adding new routes based on dynamic ones / Altering existing routes says to do.

  • Create a service that is tagged with name: event_subscriber
  • The class implementing the service extends RouteSubscriberBase
  • The service class defines its alterRoutes() method that in RouteSubscriberBase is an abstract method

In your case, the alterRoutes() method would be similar to the following one.

   * {@inheritdoc}
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('forum.index')) {
      $route->setRequirement('_permission', 'access forum pages');
    if ($route = $collection->get('forum.page')) {
      $route->setRequirement('_permission', 'access forum pages');

Instead of access forum pages, you can use a different permission, including an existing one that you think it suits more.


You can use role: authenticated user instead.


Looking for a solution to the same problem, I found this alternative: https://www.drupal.org/project/group_forum There is no documentation though.

The groups module documentation https://www.drupal.org/project/group/issues/2710909 says:

Classes of a school website is a typical usecase of the Group module.

With a teacher as the administrator, students as the members and the content as the learning material. Articles in the Group are created by the teacher and only visible to the students in the Group. Forums created in the Group are safe places to discuss the class as they are only accessible to the teacher and the students.

They are not working as private for me though.

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.

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