| Drupal
Restricting Access to Content in Drupal 8

One of our OSTraining members wanted to restrict access to certain content on his Drupal 8 site.

To do this in Drupal 8, we are going to use the Content Access module.

To follow along with this tutorial, download and install Content Access. I found no errors while using this module, but please note that currently it is a dev release. You will need to enable both options provided.

  • ACL
  • Content Access

As soon as you have enabled the Content Access module, you will be greeted with a message asking you to rebuild the permissions. This is because the module has made changes to the way permissions will work.

permissions

Now let's create a new content type that will be restricted to authenticated users only.

  • Go to Structure > Content type > Add content type.
  • Create the content type that will have restricted access.

OSTraining content type

  • On the main Content types screen click the Manage fields dropdown.
  • You will now see that you have an "Access control" option.

access control

  • Click the "Access control" link and you'll see all the ways in which you control access to this content type.
  • In this example, I want only registered members to see the content, so I'll uncheck all the "Anonymous user" boxes.

access control settings page

Drupal and Content Access are smart enough to automatically hide any content (or menu links to that content) from users who don't have permission to see it.

Here's an example of my Drupal menu for logged-in users. You can see the "OSTraining content" link.

before 

And here's that same menu for Anonymous users:

after

If you need a more refined "content access" the module also allows you restrict access Per content node if you enable this you will need to set more detailed permissions via 

  • People
  • Permissions

Using this module you can quickly set access control roles and restrictions.


About the author

Daniel is a web designer from UK, who's a friendly and helpful part of the support team here at OSTraining.