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) »
  • Postprocess hook not trigger on participant cancel (context change on cancel)
Pages: [1]

Author Topic: Postprocess hook not trigger on participant cancel (context change on cancel)  (Read 1263 times)

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Postprocess hook not trigger on participant cancel (context change on cancel)
August 03, 2010, 07:07:34 am
I am trying to run some custom code with hooks on the participant edit form (CRM_Event_Form_Participant)

I have a module implementing buildform and postprocess hooks for this form. I want to do something when the user presses 'Save' or 'cancel'. The postprocess hook triggers fine for this form when the 'save' button is pressed, but not 'cancel'.

Specifically, I am linking to the edit participant form from a custom screen I have designed, and I want the user to be returned to that screen after clicking save or cancel, so as not to disrupt their workflow. I am checking in the postprocess hook where the user came from and then doing a $session->replaceUserContext (which I found from the postprocess function in the particpant class). However, clicking cancel returns the user to the CiviEvent participant search. How do I set up something to run on cancel?

Or is there a better way to be doing this? I read someone mentioning about a context stack, but I am not sure how that works, or where the code should be placed. Any code examples would be greatly appreciated.

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Postprocess hook not trigger on participant cancel (context change on cancel)
August 03, 2010, 07:19:10 am
Well I think I partly answered my own question, in that I think I know how to push the context, but it doesn't work :(

I have the following code running in a buildform hook. The 'mycontext' is set by the url linking to the page. This code finds the context and the event id and should return to a custom url?

Code: [Select]
    if ( $formName == 'CRM_Event_Form_Participant' ) {

        $context = $form->_context;
        if ($context == "mycontext") {
            $event_id_element_id = $form->_elementIndex['event_id'];
            $event_id = $form->_elements[$event_id_element_id]->_values[0];

            require_once "CRM/Core/Session.php";
            $session =& CRM_Core_Session::singleton( );
            if ($context == "mycontext") {
                $session->pushUserContext(CRM_Utils_System::url('customurl',
                                           '&reset=1&force=1&event_id='.$event_id) );
            }
        }
    }

But nothing happens. It just goes to the standard participants search url. Anyone know why?

Also, regarding my earlier question, why does postprocess not fire when you click cancel?

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Postprocess hook not trigger on participant cancel (context change on cancel)
August 03, 2010, 10:34:57 am
I have not checked, but the common sense answer to your last question: because there is nothing to process when I press cancel?  :)
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Postprocess hook not trigger on participant cancel (context change on cancel)
August 03, 2010, 10:55:56 am
Quote from: Erik Hommel on August 03, 2010, 10:34:57 am
I have not checked, but the common sense answer to your last question: because there is nothing to process when I press cancel?  :)
Erik

Hi Erik.
Yep that does makes sense from a common sense point of view :)

What I really meant was that when you press cancel, it still posts the form data back to the same page, and then some code must be processing the form somewhere to redirect the user to another page (the participant search in the case of pressing cancel). So my question is more; Where does this processing occur in the codebase, and can I intercept it with a hook (i.e. without having to hack the core)?

Alternatively, get my extra context working and then I don't need to hook the postProcess at all

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Postprocess hook not trigger on participant cancel (context change on cancel)

This forum was archived on 2017-11-26.