Building a Custom Drupal Role with Fine-Grained Node Permissions
Drupal ships with two user roles out of the box — Anonymous and Authenticated — and neither of them does the fine-grained work most teams end up needing. The moment a content editor has to touch a landing page while leaving staff-only content alone, you need a role of your own, with node permissions checked one content type at a time.
This walkthrough covers building that role on a Drupal 10 or 11 site: creating it, mapping node access to real publishing jobs, testing with disposable accounts, and the settings that regularly catch teams out at go-live. It sits comfortably for a site builder working across a small agency roster in Melbourne, or a solo operator keeping a council site alive from a home office in Brisbane.
Why the built-in roles leave gaps
The stock roles are deliberately broad. Authenticated typically receives access to published content and, in many sites, the content overview at /admin/content. Anything added to it applies to every logged-in visitor, including a community member who signs in only to check a membership number. When a draft later leaks to the wrong person, the cause is nearly always a permission granted once at role level and then forgotten.
A custom role gives you a named bucket. You can attach it to four people today and two next quarter, and when responsibilities shift between teams, you change the bucket rather than auditing every individual account. That habit pays off in Australia, where plenty of Drupal projects are run by two or three people wearing several hats and swapping hats often.
The three setups compare like this:
| Role | Node-level reach | Typical use | Main risk |
|---|---|---|---|
| Anonymous | Published nodes of the types granted site-wide | Public pages, campaign landing pages | Grants creep upward when published content is toggled globally |
| Authenticated | All published nodes plus whatever you add on top | Logged-in members with no editorial duties | Becomes a catch-all that quietly exposes drafts and the content overview |
| Custom content editor | Selected content types, own-versus-any distinction kept intact | Writers and content coordinators | Left too broad, it quietly matches an administrator |
| Custom content manager | All editorial content types without administrative rights | Publishing leads who review and unpublish | Bypassing node access here renders every other grant pointless |
Map content types to real publishing jobs
Before touching a permission screen, write down what the site actually contains. A typical regional council site in Canberra might carry an Event, a News article, a Landing page, a Staff profile and a Job listing, and each one carries a different audience and a different risk level. A job listing that expires quietly in the background is an embarrassment, but a landing page carrying an unpublished campaign brief is a genuine problem.
Next, write down the jobs rather than the people. "Marketing coordinator", "news author", "publishing lead" and "web administrator" are stable descriptions; individual staff names are not. Where a job sits decides the permission pattern. Authors need to create and edit their own content, publishing leads need to edit anything, and administrative rights should live somewhere else entirely.
Include timing in this stage. Australian sites run on AEST and AEDT, and daylight saving shifts mean an expiry timestamp written once may behave differently for half the year. If a node should disappear automatically, decide whether that happens through cron on the server's configured timezone or through a scheduled unpublish by a publisher — and give that publisher the permission to see unpublished nodes.
Create the role and name it for the long term
Roles are managed at /admin/people/roles, and the add form is short: a label, an automatically generated machine name, a role weight and an optional assignment to the selected users. The permissions live on the role's own tab, where you can grant them at the site level or filtered by content type. A role with no permissions attached does nothing on its own, which is a useful safety net while you work through the matrix.
Give the machine name real thought, because custom code, workflow configuration and exported YAML reference the role ID rather than its label. content_editor reads clearly in a hook, in a config file and in a diff during review; Editor 2 does not. Exporting the role into version control — as most agencies in Sydney and Melbourne now do — makes the intent obvious to the next developer who touches the repository.
Assign members deliberately and record the reasoning somewhere durable. A line in the project handbook saying "content editors belong to the communications team, added by the team lead" removes an entire category of argument later, when someone needs to know why a particular account can edit a particular node.
Work through the node permission matrix
Each content type exposes a set of permissions on its edit form: view published content, create new content, edit own content, edit any content, delete own content and delete any content. Alongside these sit site-wide node permissions such as administer content, access the content overview, view unpublished content, view own unpublished content, and the powerful bypass node access grant.
The own-versus-any distinction is the heart of a granular setup. Edit own content lets a writer change only nodes they authored; edit any content lets the same writer change a colleague's draft. On a news site with three contributors, granting edit any content saves a bit of back-and-forth but removes peer review. On a site where one publisher handles final copy, granting it to everyone simply duplicates the publishing role.
View unpublished content deserves the same scrutiny. A limited version lets people see their own drafts, which is enough for an author who needs to check a preview. The broader version exposes every unpublished node on the site to everyone holding the role, including job applications that have not been published yet. Bypass node access sits above all of this, and granting it makes every other node-level grant decorative, so treat it as a break-glass permission rather than a convenience.
Test the matrix with disposable accounts
Permission checkboxes only tell you what you intended, never what the server will actually enforce. Create a throwaway account for each persona — an author, an editor and a plain registered member — and walk through the site as each one. The contributed Login As module lets you switch accounts in seconds without logging out and in repeatedly, which keeps a testing session focused.
Check the content overview for the restricted account and confirm that it lists only what that person should see. Open a node of a type they should not touch and verify it returns access denied. Open a node they may edit and confirm the form loads with the fields they expect. Where node access records exist, the node's Permissions tab shows which roles can view that specific node, which is a quick way to catch a grant that was made too broad.
Then log the outcome. The Devel and Database Logging modules give you the request-level detail, and clearing the caches after a permission change — a routine drush cr — stops stale grants confusing your results. Re-run the same checks after every core update, since permission labels and access handling have shifted between major Drupal versions more than once.
When node access needs more than a checkbox
Roles grant access at the content type level, which covers most editorial sites comfortably. Sometimes access depends on a field instead: a region, an audience, a reviewer, an embargo date. That is where node access records come in, and Drupal's core Node access module provides the machinery — realms, group IDs and priorities — while a small custom module supplies the records themselves.
/**
* Implements hook_node_access_records().
*/
function council_site_node_access_records(Node $node) {
$grants = [];
if ($node->getType() === 'job_listing') {
$grants[] = [
'realm' => 'job_listing_region',
'gid' => (int) ($node->get('field_region')[0]?->target_id ?? 0),
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
];
}
return $grants;
}
The realm name groups the grants, the group ID identifies which member of that realm may see the node, and the priority decides whose grant wins when records conflict. Once such a module is enabled, node access becomes stricter rather than looser, so re-test every role you have configured — including the ones you had not touched. It also pays to confirm your hosting runs in the region you expect, such as ap-southeast-2, so logs and cron timings line up with what your team sees on the ground.
Recommendations for putting the role into production
A permission matrix behaves like any other access control: it works well on the day it is written and drifts quietly afterwards. These are the checks that keep a custom role useful rather than dangerous.
- Start from the least privilege that lets someone do their job, then widen. Promote a trusted author to edit any content rather than spreading edit any content across the team.
- Keep bypass node access with one or two senior developers who understand what it overrides, and document the process for granting it temporarily.
- Put access the content overview and view unpublished content on a publishing role, not on every registered member, so subscribers never see editorial material.
- Create fresh test accounts before each release and walk the publishing flows again; permissions survive upgrades, but their names and their reach do not always.
- Export roles to version control and review changes the same way you review code, so permission drift shows up in a diff rather than in an incident.
- Record who holds each role and when it was last reviewed, then revisit the list at the start of the Australian financial year or whenever the team changes.
- Keep an audit trail of content actions, particularly for a site holding personal information, so decisions can be explained under the Privacy Act 1988 and the Spam Act 2003 without guesswork.
A well-scoped role pays for itself quickly. It turns a vague instruction like "the marketing people can edit the website" into something you can test, export and hand over, whether the next request comes from a council in Canberra, a client in Perth, or a community group in Hobart running Drupal on a modest shared plan.