How to show forums even if you don't have access? This is a follow up to this question.

I now know how to modify which forums are shown using the MYMODULE_preprocess_forum_list hook. But I have another scenario I can't figure out.

When you create a forum taxonomy term, you can use Forum Access module to set which users can access which forums. I have:


a board called "premium"
a role called "premium


Only premium members can access this board and this works great. But I still want the premium board to show on the forum landing page. When the user clicks on it, it must tell them they don't have access.

A workaround would be to simply give users access to those forums. Then the forum will display. Then write some other hook or chunk of code that actually stops the user when he clicks through to those pages. But it really feels to me like this should just be setting somewhere.

Am I missing something, or is my suggested solution the best route to go?

UPDATE

My problem could be solved if I could add another option to the screen below that says: "View Posts in this Forum"



Then i can specifically allow them to see the posts, but not actually click through to them.
Implementing custom permissions in Drupal 8:

https://www.aram.cz/article/custom-permissions-drupal-8

You should be able to use static permissions, which are configured in a YAML file in your custom module. From the article:


  To declare static permisisons, you need to create a file in the root directory of your custom module and name it YOUR_MODULE.permissions.yml.


'sample permission 1':
  title: 'First level permission'
  description: 'Gives first level permission to the users.'

'sample permission 2':
  title: 'Second level permission'
  description: 'Gives second level permission to the users.'

'sample permission 3':
  title: 'Third level permission'
  description: 'Gives third level permission to the users.'
  restrict access: true


Then you can check for that permission in PHP code like so:

if (\Drupal::currentUser()-&gt;hasPermission('sample permission 1')) {
  // The "sample permission 1" has been granted to the current user.
}
else {
  // The "sample permission 1" has NOT been granted to the current user.
}


I'm not sure exactly how you'll use this technique in your situation to allow users to see only a summary of forum post titles without the ability to click through and see the individual forum posts, but hopefully it will set you on the right track.