It would be nice to be able to include PHP code in the error messages, for example to let us see whether a user is logged in or not and display different messages depending on why they may not have access to a certain page.

CommentFileSizeAuthor
#2 customerror_php.patch1.14 KBgeodaniel

Comments

kbahey’s picture

Status: Active » Closed (fixed)

This module does have that ability already.

Just create two functions in the template.php file in your theme directory, and put in it:

function phptemplate_customerror_403($content) {
// Do anything you want here
return $content;
}

function phptemplate_customerror_404($content) {
// Do anything you want here
return $content;
}

geodaniel’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new1.14 KB

Khalid, thanks for the quick response! That's a great start, but I'd also love to be able to specify PHP code within the settings itself, like the way that the front_page module does it.

I've attached a patch that adds a variable for each error message to the settings page to enable PHP for that error message or not. If it's enabled then it will be run through drupal_eval() before display. I've tested this also if the message is overridden by a phptemplate_customerror_40x function and it appears to work fine in that situation too.

(The reason I'd like to have this ability too, is that we are using one theme (and subthemes) across a set of sites, and as far as I'm aware we can't override functions in a clean way to let us do different things on different sites. This would let us customise on a per-site basis.)

kbahey’s picture

Status: Needs review » Fixed

Committed to 4.7 and HEAD.

Thanks

geodaniel’s picture

Thanks for committing these changes Khalid

geodaniel’s picture

I've just noticed the changes were only on the MAIN branch - please could you also tag those latest versions as DRUPAL-4-7?

kbahey’s picture

Hmmm. Strange.

When I do cvs log, it says 4.7 is version 1.10, but the change is in 1.11.

symbolic names:
        DRUPAL-4-7: 1.10
        DRUPAL-4-6: 1.8
        DRUPAL-4-5: 1.1
keyword substitution: kv

...

----------------------------
revision 1.11
date: 2006-12-25 18:44:48 -0500;  author: kbahey;  state: Exp;  lines: +21 -23;  commitid: 7c83459061d34567;
- #104435 Allow for PHP in error messages, by geodaniel
- Tidy up some code to use t() arguments, instead of concatenation.
- Collapse the two theme functions into one with the error code as an argument.
- Document the PHP and theme functions in the README.txt file.

Anyway, I deleted the tag and retagged it, but the new release is not showing up.

I created a support request for this here http://drupal.org/node/107727

Anonymous’s picture

Status: Fixed » Closed (fixed)

  • Commit 49c98ba on 5.x-1.x, 6.x-1.x, master, 8.x-1.x by kbahey:
    - #104435 Allow for PHP in error messages, by geodaniel - Tidy up some...