By jonconnor on
I decided to give Drupal a try last week and downloaded Version 6.0. I've been theming it with some success (pure CSS), however I want to change the "Access Denied" error that is shown when "view node content" is turned off for anonymous users.
Currently, an anonymous user visiting the site sees "Access Denied. You are not authorized to access this page." I've searched through all the files in my Drupal installation and can't figure out where to modify this. I'd also like to be able to change the page title from "Access denied | Example.com" to something else.
Comments
Drupal Cookbook (for beginners)
In the Drupal Cookbook (for beginners) which can be found in the tutorials section of drupal.org, you'll find this page: http://drupal.org/node/120646 which discusses custom 403 (Access Denied) pages and 404 (Page Not Found) pages.
Definitely do it this way ^^^^^
By providing a custom 403 & 404 page, you have total control, and the use is never disoriented by seeing a page that is "outside" your site - they stay in, even when an error occurs. And it's very easy, and no hacking!
But not this way \/ \/ \/ \/ (hacking core is a sin - did anyone mention that ;-)
This method doesn't work...
This method doesn't work if you have "view node content" turned off for anonymous users. Please read my original post again carefully.
Custom 403 and 404 pages don't work in Drupal if the user can't see node content, since the error page itself is a node.
Right you are - sorry
Hmmmm.
I'd probably write a little custom hook_access module to change the access to these two pages on the fly. I think it should be a fairly easy task... how are your PHP skills?
OK....
What I did was copy the blog module from core, modified the .info and .module files to create an "error_page" node type, and added a new case to error_page_access to return true when $op == 'view'.
This was pretty easy, as mostly it just involved re-naming, search and replace, and deleting most of the unused parts of the blog module.
I am just learning how to develop in Drupal and PHP, so this was a good exercise for me.
There may be an easier way to hook directly into page_access so you could override $op == 'view' just for those specific nodes, and thus avoid introducing a special data type, but perhaps the new data type keeps the design cleaner and more transparent?
Custom error module?
For nodeless error messages (ie they don't appear in searches etc):
http://drupal.org/project/customerror
Not sure how far away a Drupal 6 version is yet though. It's what we've used since Drupal 4.6.
Or for quickly altering a few translatable strings on Drupal 6 without resorting to using the full locale module:
http://drupal.org/project/stringoverrides
--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal
i said...
I said twice it wasn't recommended! It could work, but not recommended. Didn't I say it wasn't recommended?
~silverwing - not recommended ;)
_____________________________________________
MisguidedThoughts | showcaseCMS
oops
should have read:
:) lost in translation!
not recommended....
This method isn't recommended (and there should be a better - non-hackish way - do to this, but if you open includes/common.inc go to line 390 and change this
$return = t('You are not authorized to access this page.');Remember, this is a core hack and if you upgrade, it'll be lost.
~silverwing
_____________________________________________
MisguidedThoughts | showcaseCMS
Locale module provides an alternative no-hacks solution
If the warning is run through the t() function, you could use the locale module to change the string that is returned. Although it's main function is for multi-lingual sites, the locale function offers a handy way to change certain strings (for example, changing 'Submit' to 'Save' on node forms, so that users know what the button does!)
Matthew
Nice idea
Here's another: http://drupal.org/project/r4032login
This module could probably be altered to handle 404 as well?
Another thought
I was able to update the 403 text with the following code inside the template.php of my theme:
This seems like the most
This seems like the most sensible method. Thanks! Works great!
Thanks, yes works fine, and I
Thanks, yes works fine, and I think it's the best solution (not hacking core).
Scott
Use theme name instead of phphtemplate
I used it and it work for me, Thanks !
Vikrant R
I get a Notice: Undefined
I get a Notice: Undefined index: title error. So it looks like the title is not set yet. However this works:
That's the version for Drupal 7
That's the version for Drupal 7. It works even if the anonymus users are not allowed to see any content:
Better way in Drupal 7
I'm just doing a redirect to the login page here, but...
Simple with GUI
For Drupal 7, this is incredibly simple by using only the GUI.
First create a page and add whatever message you want.
Then customize the page alias as you see fit. Copy that.
Go to admin/config/system/site-information and then go to the field set for "Error Pages" and put in your custom page alias for the 403 page.
Yes, you are correct, this
Yes, you are correct, this should work for majority of people. I however needed to redirect the user back to the page after they logged in and since setting the error page that way makes it an actually node it ends up redirecting back to the node you are using as your 403 page. Which is obviously confusing to users since they just logged in. Using mytheme_preprocess_page gives me the correct destination parameter on the access denied page.