Can I have different Access Denied pages based on the affiliate site?
davidsje - December 18, 2009 - 22:40
| Project: | Domain Access |
| Version: | 5.x-1.14 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Jump to:
Description
Is it possible to have two different access denied pages? I would like the main domain (example.com) to show one version of the access denied page, and the sub.example.com to show a different version. We currently have a custom access denied page that is set in admin/settings/error_reporting .
If you have any suggestions about this, please let me know. :)

#1
Sure. Use hook_domainbatch() to expose that variable. See API.php.
You want something similar to what is used for the frontpage:
<?php// Change the site frontpage.
$batch['site_frontpage'] = array(
'#form' => array(
'#title' => t('Site frontpage'),
'#type' => 'textfield',
'#size' => 30,
'#maxlength' => 255,
'#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'),
),
'#domain_action' => 'domain_conf',
'#system_default' => variable_get('site_frontpage', 'node'),
'#variable' => 'site_frontpage',
'#meta_description' => t('Set the site frontpage for all domains.'),
'#data_type' => 'string',
'#weight' => -8,
);
?>
#2
Thanks for the quick response :)
I'll try it out and let you know how it goes.
#3
Ack, server problems! And it probably won't get fixed until after 5pm. I'll get back to this issue in a couple weeks (after my vacation).
In the meantime, where is that frontpage code located?
Thanks!
#4
http://api.therickards.com/api/function/domain_conf_domainbatch/domain
I may just go ahead and add these, since it is pretty easy.
#5
Turns out this is really easy in the D6 version (which uses hook_domainbatch() for all configuration settings).
In D5, hook_domainbatch() only adds to the batch update screen (which may be enough). you would need additional code to domain_conf_form_alter() in order to add the setting to the normal configuration screen.
<?php// Change the site access denied message.
$batch['site_403'] = array(
'#form' => array(
'#title' => t('Default 403 (access denied) page'),
'#type' => 'textfield',
'#size' => 30,
'#maxlength' => 255,
'#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'),
),
'#domain_action' => 'domain_conf',
'#system_default' => variable_get('site_403', ''),
'#variable' => 'site_frontpage',
'#meta_description' => t('Set the access denied message for all domains.'),
'#data_type' => 'string',
'#weight' => -8,
);
?>
To really make this work, the domain_conf_form() changes from D6 would have to be backported, which isn't likely to happen.
#6
The patch to backport is #405148: Remove hook_form_alter from Domain Conf (patch from #2)
#7
Sorry about the delay - I've been on vacation. Thanks for your repsonses, they're helpful.
I haven't added the patch yet - I don't know if it's needed. I can set the custom access denied page for the main page at admin/settings/error_reporting. Then with the code you provided, I should be able to set the subdomain's access denied page on the domain settings page.
However, I put the code you provided (from #5) into the domainbatch function in domain_conf.module and ran update.php. The new option is still not showing up in the domain settings.
Anything I might have forgotten to do?
#8
I did make one change to the code you provided. There was a #variable set to 'site_frontpage', and I changed it to 'site_403'. However, the option still doesn't show up on the subdomain's domain settings page (admin/build/domain/conf/1).
<?php// Change the site access denied message.
$batch['site_403'] = array(
'#form' => array(
'#title' => t('Default 403 (access denied) page'),
'#type' => 'textfield',
'#size' => 30,
'#maxlength' => 255,
'#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'),
),
'#domain_action' => 'domain_conf',
'#system_default' => variable_get('site_403', ''),
'#variable' => 'site_403',
'#meta_description' => t('Set the access denied message for all domains.'),
'#data_type' => 'string',
'#weight' => -8,
);
?>
#9
I misunderstood why the patch was needed - I'll add it straight away (as I don't have access to the batch update screen on this site).
Thanks!
#10
I tried adding the patch and here is the output:
/var/www/drupal-5.1/sites/all/modules/domain$ patch -p0 < 405148-conf.patch
patching file API.php
Hunk #1 succeeded at 445 (offset -4 lines).
can't find file to patch at input line 37
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: domain_conf/domain_conf.admin.inc
|===================================================================
|RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_conf/domain_conf.admin.inc,v
|retrieving revision 1.7
|diff -u -p -r1.7 domain_conf.admin.inc
|--- domain_conf/domain_conf.admin.inc 25 Mar 2009 17:31:44 -0000 1.7
|+++ domain_conf/domain_conf.admin.inc 25 Mar 2009 20:01:20 -0000
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
3 out of 3 hunks ignored
patching file domain_conf/domain_conf.module
Hunk #1 FAILED at 125.
Hunk #2 succeeded at 380 (offset 206 lines).
Hunk #4 succeeded at 414 (offset 206 lines).
Hunk #6 succeeded at 448 (offset 206 lines).
misordered hunks! output would be garbled
Hunk #8 FAILED at 386.
Hunk #9 FAILED at 403.
Hunk #10 FAILED at 419.
Hunk #11 FAILED at 434.
Hunk #12 FAILED at 451.
Hunk #13 FAILED at 470.
Hunk #14 FAILED at 486.
Hunk #15 FAILED at 498.
9 out of 15 hunks FAILED -- saving rejects to file domain_conf/domain_conf.module.rej
I understand the first error because there is no file with that name. I'm using Domain Access 5.x-1.14, is that what this patch was written for? I'm not very experienced with patches, so I'm not sure how to proceed. Any help would be much appreciated. Thank you.
#11
The patch is for D6. The patch itself needs to be ported to D5.
Otherwise, the code I gave you using hook_domainbatch() will appear as a Batch option, not under Domain Conf settings.
#12
Closing this issue -
I got access to the "Batch Updating" portion of Domain Access, and used your suggestion of adding that block of code to domain_conf.module. It works like a charm! For now, I'm happy with being able to set this in Batch Update.
Thanks :)
#13
So I guess I jumped the gun when I said it worked. It seems that the settings on admin/settings/error-reporting don't play nice with the code I added to the Domain Access module.
If the setting in /admin/settings/error-reporting is left blank, the specified error pages on the batch updating (in Domain Access) work only for the subdomain. When you specify a page for the main domain, my error page appeared incorrectly for anonymous users (instead of showing the content of my custom error page, it showed just "Content" as the title and "2" as the body).
Any ideas on how to deal with this?
Thanks :)
#14
Proper hook_domainconf() on the 'site_404' and 'site_403' variables (in D5). Or hook_domainbatch() in D6.
#15
For D6, you can also try http://drupal.org/node/713026.