Field Permissions: How do I Grant Access to Individual Drupal Fields?

Published May 27, 2022
Updated Jun 30, 2022
By Simon

Field permissions module is one of those modules that truly unleashes Drupal's power. It isn't needed on every site, but if you want or need more fine control permissions of individual fields or entities, this is the module for you.

Some use cases for Field Permissions are:

  • Needing to hide a field for anonymous users on the front-end.
    • Add new fields to content for testing purposes before released to the public.
    • Provide extra information to registered users.
  • Restricted edit access to certain user roles for individual fields.
  • Allow anonymous users to create values for fields.

The great thing about the module is if you don't set special permissions for a field then the default settings are used which are the ones set at the content type level. Let's take a look at the module in a bit more detail.

Info

Field Permission
https://www.drupal.org/project/field_permissions

Actively maintained No, Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.
About 80,000 sites report using it at the time of writing.
This module has been around for a long time and I would say it is feature complete and very stable.

Requires No extra requirements.
Libraries No library.

Install either using the UI or composer.

Basics

Once installed you need to navigate to the manage fields pages for the content type of the field you want to set special permissions for. For this example, I am using a notes field in the Article content type.

Manage >  Structure > Content types > Article > Manage fields
/admin/structure/types/manage/article/fields

Image
manage feildsin Drupal CMS

Click on the edit field button and then find the field settings section of the edit form.

If you have many roles, you can set all the role's permission. Just remember once explicitly set, you must enable every permission for each role, otherwise, the users from the different roles will not be able to see the field even if they have edit access to the content type.

If you run a smaller site and most users have the administrator role then you can use the Private: Only author and administrators can edit and view, which is a nice feature.

Image
drupal field permissions with private settings

However, if you have more fine-grained roles you will need to use the Custom permissions: Define custom permissions for this field settings and check what roles have what permissions as illustrated below.

Image
custom field permissions with editor role

Advanced Settings and Reports

You can access these from the module extend page directly or use the toolbar and default Drupal navigation.

Module Permissions

If you have more than one type of administrator then you may need to give another role access to administering the module's functionality.

Manage >  People > Permissions
/admin/people/permissions/module/field_permissions

Field Permissions Report

The module adds a report page to the field list section, this is helpful to see an overview of the field permission settings.

Manage >  Reports > Field list > Field permissions
/admin/reports/fields/permissions

That's it for the Field Permission module. It is the sort of module that allows you to make better user experiences, be it the experience of an anonymous user or that of a member or administrator of your site or application. I personally link being able to add a field that is only shown to logged-in users but I have also built content types that have allowed anonymous users to add information to a content type, one such example is using a content type for anonymous users with a special link to add a review. 

Thanks for reading and be sure to sign up for the newsletter if you are interested in design and technology. I write about front-end development. Until next time, seize the day!

Tags