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
- 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
- Next we need to create the content type that will be used to share within the groups. Navigate to Structure > Content types
- I will name this content type File
- You can fill in the settings in the tabs as you please
- You can now add any fields you like, but as in the example I’m following I will add a File field. Click
- Below Add a new field select File
- Label the field File
- Under Upload destination select Private Files (see the remark I made about this above)
- 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
- 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
- You can leave the setting on the next screen as is. Click on
- To test if this works we need to create a Group (Client). Navigate to Groups
- Click on
- Enter any title and click on 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
- Next we need to place a block with which users can add content to the group. Navigate to Stucture > Block Layout
- Click on 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
- You can change the title of the block or uncheck Display title
- Below Select a group value: select Group from URL
- 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
- 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
- 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
- Next to Fields click Add
- Search for File and check File
- Click on
- Leave settings as is and click on
- 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
- Below Filter by plugin check Group node (File)
- Click open the Advanced tab again
- Click Add next to Contextual Filters
- Search for parent and check Parent group
- Below When the filter is not available select Provide default value
- Under Type select Group ID from URL
- 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
- In the Group types tab check Client
- 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.
What a great content this website offers. Thanks so much for that Robert! You are a great source of inspiration for me. I have a question: how to make group and nodes private/public? Like private posts in a public group? Thanks so much for all this content!
I suppose I'll quickly find the answer but it could be nice to talk about ;-)
Have a great day.
OK I got it.
It is because I used Organic Groups in the past (that is a bit different).
Just go in the group and handle permissions! As simple as that!
Thanks for all the compliments and good to see you've solved this issue yourself :)
By any chance, do you have an idea how to create private/public polls?
Because as author and I don't know why is not by default on Poll, it cannot be referenced as a plugin.
Nothing is perfect.
Except this article :-p
Solution: use webforms! What do you think of that? :-D