CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • pageRun Hook on Contribution Pages
Pages: [1]

Author Topic: pageRun Hook on Contribution Pages  (Read 889 times)

dwatts3624

  • Guest
pageRun Hook on Contribution Pages
October 28, 2010, 04:00:57 pm
I'm currently trying to customize the contribution page a bit but am running into some issue with the pageRun hook.

Just to confirm that everything is working, I am running the following function (with Drupal module named 'civicrm_hooks')

Code: [Select]
function civicrm_hooks_civicrm_pageRun( &$page ) {
 
drupal_set_message('success');

}

This works fine on the profile pages but does respond on contribution pages.

Am I using the wrong hook or is this a bug?

dwatts3624

  • Guest
Re: pageRun Hook on Contribution Pages
October 29, 2010, 04:12:02 am
I should also note that I'm working on an overridden template: CRM/Contribute/Form/Contribution/1/Main.tpl & MembershipBlock.tpl

dwatts3624

  • Guest
Re: pageRun Hook on Contribution Pages
October 30, 2010, 01:01:50 pm
Okay, I'm assuming this one got neglected because it was an erroneous question.  ;)

The pageRun() hook doesn't run on forms, right?  I used buildForm() instead and got it to respond.

If anyone's interested, the reason I was trying to get this hook to run was because I wanted to restrict access to a contribution page (we don't want to public to see the details of our membership financials).

Part of the answer to my original question ended up being listed here: http://wiki.civicrm.org/confluence/display/CRMDOC32/Linking+Profiles

Between the information listed there and some Drupal forum posts, I came up with the script below (added to my "civicrm_hooks" module")

Just to give me a bit more flexibility I added a permission for "access membership page".  And then in the CiviCRM hook, I'm sending users without permission to access the "CRM_Contribute_Form_Contribution_Main" with ID=2 (in this case) to an access denied page.  Coupled with the LoginTobogggan module (which loads a login form into access denied pages and redirects upon successful authentication) this works great!

Code: [Select]
function civicrm_hooks_perm() {
return array('access membership page');
}

function civicrm_hooks_civicrm_buildForm($formName, &$form) {
 
  if ( $formName == 'CRM_Contribute_Form_Contribution_Main' &&
  $form->getVar( '_id' ) == 2 ) {

if (! user_access('access membership page')) {
drupal_access_denied();
}
}
}


dwatts3624

  • Guest
Re: pageRun Hook on Contribution Pages
October 30, 2010, 03:42:38 pm
Whoops.  I just noticed that the page was rendering twice.  How embarrassing!

Edited code below...

Code: [Select]
function civicrm_hooks_perm() {
return array('access membership page');
}

function civicrm_hooks_civicrm_buildForm($formName, &$form) {
 
  if ( $formName == 'CRM_Contribute_Form_Contribution_Main' &&
  $form->getVar( '_id' ) == 2 ) {

if (! user_access('access membership page')) {
drupal_access_denied();
exit;       
}
}
}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • pageRun Hook on Contribution Pages

This forum was archived on 2017-11-26.