How-to: Group Content Access capabilities in Drupal 8

In this post, I shall brief you on how to create a group, a group content, and control it's visibility in Drupal 8 based on your needs.

Required Modules

Installing Organic Groups and Private modules

These modules can be installed using the same procedure as we do for any other Drupal 8 module. You may refer Installing Drupal 8 Modules Documentation for the same.

Once the necessary modules have been installed successfully, we would proceed ahead to create and configure our group and populate it with the content along with the appropriate configurations.

Creating a Group

In this section, we will learn how to create a structure for the group (we call it as an audience) and later create a private group that we will use for the future demonstration. To do so, we follow the below steps:

  • Navigate to Manage -> Structure -> Content Type -> Add content type or directly navigate to /admin/structure/types/add path of your Drupal 8 installation.
  • To control the default privacy setting of any group that is supposed to be created in the future, and can be modified or overridden later, navigate to the Publishing options tab (at the bottom of the form), and select the appropriate radio button against the Privacy section. In our case, we have selected Enabled (private by default) as demonstrated in the below screenshot:
Privacy options for an organic group in Drupal 8
  • Next, navigate to the Organic groups tab and select Group checkbox if you wish to consider it's content to behave like a Group, as demonstrated in the below screenshot:
Group or Group content in Drupal 8
  • Now, our audience content type is to hold different groups. To do so, navigate to Manage -> Content -> Add content -> Audience or directly use /node/add/audience path, and create a new group or groups that are supposed to be used at later stage when creating blogs; specific to each of the groups.
  • In our case, we created two audience groups Managers and Technical Architects that are intended to hold managers and technical architects specific blogs or information respectively.

Once the preceding steps have been commenced, we are good to configure a content type that is supposed to hold group content or posts; possessing restricted access based on the group audience.

Creating a Group Content

Before we start populating group content, we need to create a content type and configure it appropriately so that it can hold group specific content.

In order to create a content type for group content, we follow below steps:

  • Navigate to Manage -> Structure -> Content Type -> Add content type or directly navigate to /admin/structure/types/add path of your Drupal 8 installation. We named it as Blog due to the fact that we want different blogs to be accessible to different Audience.
  • To control the default privacy setting of any group content that is supposed to be created in the future, and can be modified or overridden later, navigate to the Publishing options tab (at the bottom of the form), and select the appropriate radio button against the Privacy section. In our case, we have selected Enabled (private by default) as demonstrated in the below screenshot:
Privacy options for an organic group content in Drupal 8
  • Next, navigate to the Organic groups tab and select Group content checkbox if you wish to consider it to behave like a content of a group; which will intern allow you to select a Target bundle from the Target bundles field. This field populates the list of content types or bundles that can be considered as group bundles (in our case, we have Audience as such a bundle). Select the desired bundle from the list and hit Save content type button as demonstrated in the below screenshot:
Group content bundle in Drupal 8

Once the preceding configurations have been completed, we are good to create a group content; specific to a group (in our case, we will create a private blog that is supposed to be accessible ONLY to the members of the group Managers).

  • To do so, we navigate to Manage -> Content -> Add content -> Blog or directly use /node/add/blog path and fill in all the necessary information, especially the section demonstrated in the below screenshot:
creating a group content in drupal 8

 

Note

The process of adding group members, or allowing members to subscribe to a specific group has not been covered in this write-up.