Allow displaying a custom message on the Access Denied (on403) error pages

Created on 3 January 2025, 18 days ago

Problem/Motivation

Now each 403 error page can display just a static hardcoded text:

Access denied
You are not authorized to access this page.

But pretty often it is required to show a custom message to the user, explaining why the access is denied, especially in contrib modules with custom business logic.

And seems Drupal provides no way to pass the custom message to this page! So the developers should invent their own ways to display the standard "Access denied" page but with a custom message text.

So, let's fix this by adding the ability to display the custom message to the Drupal System module?

Steps to reproduce

1. Have a desire to display a custom "Access denied" message to the user.

2. Throw a new AccessDeniedHttpException() with a custom message like this:

  throw new AccessDeniedHttpException('The credentials to My Service are not valid, please check the MyModule configuration');

3. See the standard "Access denied" Drupal page with no custom message text.

Proposed resolution

Extend the function DefaultExceptionHtmlSubscriber::makeSubrequest() to check the exception message and display it on the "Access denied" page, if the message is not empty.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

system.module

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024