How to create groups within Drupal which can share nodes (and files) privately

Thanks to all the free Drupal modules available you can use Drupal for almost anything, such as a private area where you can share specific nodes with groups of users.
Robert Roose
By Robert Roose

How to create groups within Drupal which can share nodes (and files) privately

Say, for example, that you want to share content (like PDF files) with your clients. You don’t want them to be publicly available, because they are for your clients eyes only. You also don’t want clients looking at each other's files. This is where the Group module comes in. Here you can create different group types (such as client) with which you can create a separate group for each client you want to share files with. 

In this tutorial I will show you how to set up the group module which can be used to share nodes privately to a set group of users.

Setting the Privates Files Directory

If you only want to share nodes within a group you can ignore this part. If you want to share files you need to create a private files directory. Else users without the correct permissions would still be able to access the files by guessing the correct URL of the file and typing it in the address bar of their browser. Learn how to set up a private files directory for Drupal

Setting up the Group module

  • Install the Group module
  • Enable the Group node module
  • Navigate to Group > Group types
  • Click + Add group type
  • Name the group type. I will follow the example I mentioned above and name it Client
  • You can enable or disable Create a new revision when a group is modified as you please
  • Enabling The group creator automatically becomes a member can be helpful when you want users to create their own groups
  • It’s best to enable Group creator must complete their membership in case you have required fields on a users’ profile page
  • Enabling both Automatically configure an administrative role and Automatically assign this administrative role to group creators is very useful, because now you can create admin permissions within the group
  • Click Save group type
  • Next we need to create the content type that will be used to share within the groups. Navigate to Structure > Content types
  • Click + Add content type
  • I will name this content type File
  • You can fill in the settings in the tabs as you please
  • Click Save and manage fields
  • You can now add any fields you like, but as in the example I’m following I will add a File field. Click + Add field
  • Below Add a new field select File
  • Label the field File
  • Click Save and continue
  • Under Upload destination select Private Files (see the remark I made about this above)
  • Click Save field settings
  • In the next screen you can change the settings as you please. Below Allowed file extensions I’ll put pdf as I only want to share PDF files
  • I like to name the File directory something more generic like files
  • I also check Enable Description field because then you can label the fields with something that makes more sense instead of just showing the filename
  • Click Save settings
  • What we need to do next is to make nodes of this content type available to the Client group we’ve created. Navigate to Group > Group types > Client and click on the Content tab
  • Click on Install next to Group node (File)
  • You can leave the setting on the next screen as is. Click on Install plugin
  • To test if this works we need to create a Group (Client). Navigate to Groups
  • Click on + Add group
  • Enter any title and click on Create client and complete your membership
  • Enter any URL alias. This will be shown in the address bar of the browser when viewing the group and click on Save group and membership
  • Next we need to place a block with which users can add content to the group. Navigate to Stucture > Block Layout
  • Click on Place block next to the title of the region you want to place the block in. In most cases you want to choose Content
  • Next to Group operations click Place block
  • You can change the title of the block or uncheck Display title
  • Below Select a group value: select Group from URL
  • Click Save Block
  • Click Save Blocks
  • You can now navigate to Groups and click on the group you’ve added in a previous step
  • On this page you will see an extra menu with the options Add File and Leave group
  • Click Add file
  • Fill in the (at least) the title (can be anything) of this node and add a file (can be anything) and optionally you can enter a Description for the file you’ve added
  • Click Save
  • If we now go back to the Group page we don’t see the File we just added. For this we need to create a view. Navigate to Structure > Views
  • Click + Add view
  • Under View name enter Client files
  • Below View settings set Show to Content, type to File and sort to Newest first
  • Below Block settings check Create a block
  • Set Display format to Unformatted list of Fields
  • Remove the value below Items per block so all files will be shown instead of just 5
  • Click Save and edit
  • Next to Fields click Add
  • Search for File and check File
  • Click on Add and configure files
  • Leave settings as is and click on Apply
  • Because we are using the description of the file the title is not needed anymore. Click on Content: Title
  • Click on Remove
  • Open the Advanced tab on the right side
  • Click on Add next to Relationships
  • Search for group and check Group content for Content
  • Click Add and configure relationships
  • Below Filter by plugin check Group node (File)
  • Click Apply
  • Click open the Advanced tab again
  • Click Add next to Contextual Filters
  • Search for parent and check Parent group
  • Click Add and configure contextual filters
  • Below When the filter is not available select Provide default value
  • Under Type select Group ID from URL
  • Click Apply
  • Click Save
  • Next we need to show this block on the Group pages. Navigate to Structure > Block layout
  • Click Add block next to the region you want to add this block. I’ll place the block in the Content region
  • Next to Client files click on Place block
  • In the Group types tab check Client
  • Click Save block
  • Click Save blocks
  • Navigate to Groups and click on the group you’ve created a File for in a previous step

If all went well you now should see a block with Files specifically assigned to this group. You can now add groups and then add files and users to those groups.

If you have any questions about this tutorial please let me know by leaving a comment. Also don’t forget to subscribe to my Drupal Newsletter or Drupal RSS Feed.

More Drupal tutorials

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.