Overview

I had the opportunity to use custom permissions in a Drupal custom module, so here are my notes.

Background

In the following article, I introduced a module that executes GitHub Actions from Drupal.

However, the permission was set to administer site configuration, so only users with administrator privileges could execute it.

The commit addressing this issue is as follows.

https://github.com/nakamura196/Drupal-module-github_webhook/commit/c3b6f57bebfeda0556c929c8ed8ed62a0eb0a5c4

Method

Below, I share the response from ChatGPT 4o.


In Drupal’s _permission, you can set values to configure specific access permissions. This controls whether users with specific roles can access that route.

The main values that can be set for _permission are as follows:

Common Permissions

Drupal provides several standard permissions. Here are examples of commonly used permissions:

  1. administer site configuration - Permission to manage site-wide configuration
  2. access content - Permission to access content
  3. administer users - Permission to manage users
  4. create content - Permission to create content
  5. edit any content - Permission to edit any content
  6. delete any content - Permission to delete any content
  7. view user profiles - Permission to view user profiles
  8. administer permissions - Permission to manage permissions
  9. access administration pages - Permission to access administration pages
  10. administer taxonomy - Permission to manage taxonomy

Custom Permissions

You can also create module-specific permissions. For example, you can create custom permissions for the github_webhook module and use them in _permission.

To create custom permissions, define them in github_webhook.permissions.yml as follows:

acctdreieestssslcterrg:iiipct'tthAiucoabcnce:cwsees'sbAshGl:oilotoTkHwRusUsbEeutWsteeibrnhsgosot:koSaectcteisnsgsa'ndmodifyGitHubWebhooksettings'

Then, set this custom permission in routing.yml:

gitpdrhaeeutf__q_bhaftup_:uoiiewlrtrretmlemb/s:emiha::esodnsom\'tikiDGso.nri:ns/ut:ecpHtoau'tnlbaif\cnigWcggiees/tbs:ghhsiuotbogh_kiuwtbeSh_beuwhtbeotboiwhkneo\gboFshko'o'romk\SseettttiinnggssF'orm'

Summary

For _permission, you can set standard Drupal permissions (such as administer site configuration). You can also define custom permissions and create access permissions specific to that module or feature.

Configuration

As a result, the following permissions were added, allowing access to be granted for specific roles.

Summary

I hope this serves as a useful reference for building and using Drupal custom modules.