Parts of this article were generated by AI.

Overview

When creating configuration pages for custom modules in Drupal, you may want to allow non-admin users to access them. This article explains how to solve this issue, using the GitHub Webhook module as an example.

The Problem

Initially, the routing configuration was as follows:

#gigtpdrihaeetutf__q_hbhaftupu_:uoiiebwlrtrr_etmlemwb/s:emieha::esbodnshom\'tiokiDGsoo.nri:nks/ut:.ecpHrtoau'otnlbauif\dtnigWmiggieins/tbng:ghhi.iuosytbotmh_keluwrbeS_beswhtieottboiehkno\gcoFsoko'n'rfmi\gSuertattiinogns'Form'

With this configuration, only administrators with the administer site configuration permission could access the page, and general users could not.

Solution 1: Creating a Dedicated Permission

First, create a dedicated permission. Create a new github_webhook.permissions.yml file:

acctdeiestsslcerg:iipt'thAiucobcne:wses'bAhGloilotokHwusbuestWeteribsnhgotsoo:kaScectetsisngGsi'tHubwebhookconfiguration.'

Then update the routing file:

#gigtpdrihaeetutf__q_hbhaftupu_:uoiiebwlrtrr_etmlemwb/s:emieha::esbodnshom\'tiokiDGsoo.nri:nks/ut:.ecpHrtoau'otnlbauif\ctnigWciggieens/tbsg:ghhs.iuoytbogmh_kiluwtbeSh_beuwhtbeotboiwhkneo\gboFshko'o'romk\SseettttiinnggssF'orm'

The Discovery: /admin Path Restrictions

However, this change alone did not solve the problem. In Drupal, paths under /admin are treated as the admin area and are subject to additional permission checks.

Solution 2: Changing the Path

As a fundamental solution, move the path outside the admin area:

#gigtpdrihaeetutf__q_hbhaftupu_:uoiiebwlrtrr_etmlemwb/s:emiehg::esboinshot\'tiokhDGsoo.uri:nksbut:.e-pHrtwau'otelbauib\ctnhgWcigoieensotbsg:khhs./uoysbogme_kiltwtteShibeunhtbgotsoiw'kne\gbFsh#o'oroCmkh\aSsneegttettdiinntggossF'oourtms'idetheadminpath

New Problem: Disappearance from the Admin Panel

After moving the path, the item disappeared from the configuration list in the admin panel.

To solve this issue, create a github_webhook.links.menu.yml file:

gittdrpwhieoaeutsuriblcteg_erenhw:i_ttepn::b'tahGims1oioey0otn:skH:t.ugesb'imeCt.tWohatenudibfbmnhi_igogwnsoue_:krbcehoSoneGoftikitt.giHs_nuesgbtestr'wivenibgchseosoksettings.'

This allows the menu item to appear under “Services” in the admin panel while keeping the path at /github-webhook/settings.

Customizing the Placement

You can adjust the display location within the admin panel by changing the parent value:

  • system.admin_config_services - Under “Services”
  • system.admin_config_system - Under “System”
  • system.admin_config_development - Under “Development”
  • system.admin_config - Top level under “Configuration”

Instead of using a .links.menu.yml file, you can also use a hook in the module file:

f}un$]Icl;mti'''''pintrdpwlokioeaeenstusrim[ltcegeg'eernhnig'_ittttinp''sht=atuh>mi==hbueo>>o_b''now_G''1kewi=s0_bet>=y,mhbH>seohu'tnoobg'eukoiCm__kWto.lm.ehnaiesbufdnnehbimkuto_gis_towun_liker_dinbecingShoskseoGncs'toifo_]tktivdi.Hgei=nsu_rsgebsec[stedo'twr_v,ievaenbilrghctesoeed'osr_,k'(a,)ls.teetrt(i&n$glsi.n'k,s){

Granting Permissions

Finally, grant the newly created access github webhook settings permission to the appropriate roles on the “User Permissions” page in the admin panel.

Summary

To allow non-admin users to access configuration pages in Drupal:

  1. Create a dedicated permission - Define a new permission in the .permissions.yml file
  2. Change the path - Move from under /admin to a regular path
  3. Add menu links - Display the item in the admin panel using .links.menu.yml
  4. Grant permissions - Assign the permission to appropriate roles in the admin panel
  5. Clear cache - Apply the changes with drush cr

These steps enable flexible permission management, allowing you to implement access control tailored to your project’s needs.

Don’t forget to clear the cache with drush cr whenever you make changes!

Final Notes

There may be some inaccuracies, but I hope this is helpful as a reference.