I'm trying to modify the text that shows on the standard Access Denied page. I created a module and tried to extend the core class but while module installs fine the page does not get modified. My first question is can Access denied be customized?
2 Answers
Access Denied is an exception and if you want to have control over any aspect how this is handled the best place is an exception event subscriber, see How can we catch the acces denied exception in drupal 8 for the general aspects or Returning alternate HTTP codes for unpublished content in Drupal 8 for an example how to change a 403 to a 404 exception.
I'm trying to modify the text that shows on the standard Access Denied page?
This question is specific for the text, see this answer for a 404 message, How to change page not found page error message in drupal 8?, replace it with 403 for an access denied message.
My first question is can Access denied be customized?
The standard way is of course in the basic site settings admin/config/system/site-information.
-
The How to change page not found was what I was looking for thanks! May 5, 2017 at 0:31
You can customize the Access Denied Page at the theme level. Use the following file name suggestion page--403.html.twig
, while
page--4xx.html.twig
my be used for any 400-level status code.
Docs: https://www.drupal.org/docs/theming-drupal/twig-in-drupal/twig-template-naming-conventions