Group's content page of the Marketing team, seen by two members. Bruno Lima, chosen for the task list Proposal 2027, sees six items: both task lists and the four tasks. Carla Dias, a member of the same group, sees three: the task list Website relaunch and its two tasks.
The Group content restriction tab of a content type's edit form: Who may see a piece of this content, set to The people of the content it references, the field to follow, List, and Update the existing content of this type now, checked.

This project is not covered by Drupal’s security advisory policy.

Group Content Restriction lets a Group keep some of its content to some of its members. A node is seen only by the people chosen on it, and the content that follows it takes the same restriction: mark a task list as visible only to two people, and its tasks disappear for everyone else in the group, from pages, views, Group's own content pages and search. It never grants access Group does not give; it only takes some away.

Features

  • 🔒 People chosen on the content. A user reference field on a content type holds who may see each node. With people in it, everyone else in the group, group admins included, gets access denied on the node and stops finding it in listings; with the field empty, the node is open to its group as before.
  • 🌳 Content that follows other content. A content type can follow the node one of its fields references, through any number of levels, so the tasks of a restricted list, and the notes of those tasks, take the list's restriction with no field of their own to keep in step.
  • 🔒 Every way in is covered. Entity access on every operation, a query alter on access-checked entity queries and views, Group's content pages and relationship forms, flags, and a field the people pick from that offers only the members of the content's group.
  • 🔒 Only those allowed choose. Choosing the people, or moving content into or out of a restricted node, needs the Restrict group content group permission; the person who restricts a node is added to its people, so nobody locks themselves out.
  • ⚙️ Configured on the content type form. A Group content restriction tab picks the mode and its field, and updates the existing content in a batch when the settings change.
  • ⚡ Stored, not computed on every query. The restriction of each node is kept in an index the module writes on every save, so a listing filters with one condition instead of following each node's chain of references.
  • 🧩 Group Content Restriction Search sub-module. A Search API processor that filters results inside the search backend, so counts, facets and paging agree with what the account may see. It is the companion of Search API Group Access: with both processors on one index, a search returns only the content of the account's groups, and of that, only what the account was chosen for.

 the task list Website relaunch and its two tasks.

Quick start

composer require drupal/group_content_restriction:^1.0@beta
drush en group_content_restriction
  1. On the content type that holds the people (a task list, for example), add a User reference field with an unlimited number of values, and set its Reference method to Members of the content group.
  2. Go to Structure > Content types, edit that content type, open the Group content restriction tab, choose The people chosen on it and the field, and save.
  3. For content that should follow it (the tasks), edit its content type, choose The people of the content it references and the reference field, and save.
  4. Grant Restrict group content to the group roles that may choose people. Group gives it to every admin role.
  5. Edit a node, pick two members in the people field, and save: the other members of the group get access denied on it and on the content that follows it.

 Who may see a piece of this content, set to The people of the content it references, the field to follow, List, and Update the existing content of this type now, checked.

Good to know

  • Core's Bypass content access control permission opens restricted nodes by their URL, because core allows it before any module is asked. Grant it only to people who may see everything; the module's own Bypass group content restriction permission is the one meant for that.
  • A restriction is enforced on save, through validation, and by access. Code that changes a reference or the people field and saves without validating is not judged.
  • Search API indexes do not go through the query alter: add the sub-module's processor to every index of nodes or comments, and reindex it before the first node is restricted.
  • Code that reads nodes with its own SQL, outside an access-checked query, has to add the module's condition itself; the README shows how.

Additional requirements

  • Drupal 11.1 or later.
  • Group 3.3 or later, with its Group Node sub-module.
  • Search API, only for the Group Content Restriction Search sub-module.

Recommended modules/libraries

  • Search API Group Access: filters Search API results by Group access. Its Group access processor and this module's Group content restriction processor are made to run on the same index, each adding its own condition: the first keeps a search to the groups the account may see, the second takes out the restricted content the account was not chosen for.
  • Group Entity Reference Filter: limits a reference field's options to the content of the group the edited entity belongs to, such as the task lists a task can be put in.

Similar projects

  • Subgroup: makes groups children of other groups. Content can be kept to some members by moving it into a child group with those members; pick it when the smaller circle is a lasting group of its own, and this module when it is chosen piece by piece inside one group.

Community documentation

  • README: configuration, permissions, the index and its re-checks, every access path, the API for code that reads nodes outside the entity API, and the Search API sub-module.

Supporting this module

Developed and maintained by Bloomidea. Bloomidea offers support and custom development for this module.

Supporting organizations: 
Development and maintenance

Project information

Releases