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) »
  • Strange Hook anomolies and desparate tests to a possible solution
Pages: [1]

Author Topic: Strange Hook anomolies and desparate tests to a possible solution  (Read 707 times)

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 12:42:28 pm
Hello everybody.

I have been playing with hooks, well, that is a lie, I have been fighting with them, shouting and using terrible language at them.

They wouldn't fire, you see. Nothing. I tried various ways, I read, ok, more like indepth skimming the documention. But I just could not make them fire.

The constructor would be called, but the hook wouldn't.

This wouldn't work
Code: [Select]
function hook_civicrm_buildForm( $formName, &$form ){
   echo "I AM HERE"; exit;
}


In a desparate measure I tried.
Code: [Select]
function civicrm_buildForm( $formName, &$form ){
   echo "I AM HERE but I don't think I should be"; exit;
}

It worked

I have also test this now with
Code: [Select]
function civicrm_postProcess( $formName, &$form ){
  echo "YAY";exit;
}

function hook_civicrm_postProcess( $formName, &$form ){
  echo "BOOO";exit;
}


Can some one explain to me why the former does not work, yet the latter does work. Why does the documentation say to prefix the hooks with hook_ when this does not work?
If I have missed something labelled "read this you stupid developer before hooking in", I apologise and if can send me a link to this, I can bring my stress levels down :)


cheers
You did not answer the verification questions correctly - sigh

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 02:28:31 pm
The word {hook} = the name of your module - this is a convention in drupal so many people know it from there but it may not be well documented in Civi documentation.

So, if your module is called 'hook' then 'hook_civicrm_buildForm()'  is the correct function name. If you look @ something like

https://github.com/eileenmcnaughton/gift_memberships

You will see that the folder name, .info & .module filenames & the function prefixes are all 'gift_memberships'
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
Re: Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 02:38:15 pm
Thanks Eileen, that makes sense.

Just to show I am not a total idiot, I am using Joomla, hence why had no idea about this. I would recommend adding something in bright red pt 32 marquee blink text to let the Joomlaers know :)


*other question removed as it was stupidity on behalf :) *
« Last Edit: June 12, 2012, 02:48:34 pm by usr238496 »
You did not answer the verification questions correctly - sigh

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 02:41:05 pm
For joomla, it depends of the version I think. Check out our chapter about it & the wiki
http://book.civicrm.org/developer/techniques/hooks
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 02:48:16 pm
I've never seen that second syntax before - I've never seen CiviCRM refer to 'civi' rather than CiviCRM - there's not a missing '=' in your module or another is there - ie

if($formname = 'civi_event_registration'){

rather than


if($formname == 'civi_event_registration')

causing the form to be renamed.

It would be great if you could update whatever documentation you used with the missing information for Joomla! people
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

usr238496

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 0
  • CiviCRM version: latest
  • CMS version: joomla2.5
  • PHP version: 5 something
Re: Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 02:49:48 pm
Quote from: Eileen on June 12, 2012, 02:48:16 pm
I've never seen that second syntax before - I've never seen CiviCRM refer to 'civi' rather than CiviCRM - there's not a missing '=' in your module or another is there - ie

if($formname = 'civi_event_registration'){

rather than


if($formname == 'civi_event_registration')

causing the form to be renamed.

It would be great if you could update whatever documentation you used with the missing information for Joomla! people


You replied before I had a chance to modify my question, I realised it was my mistake. The formName IS coming through correctly before and after submission. I was accessing the wrong array element doh
You did not answer the verification questions correctly - sigh

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Strange Hook anomolies and desparate tests to a possible solution
June 12, 2012, 03:07:18 pm
 ;D
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Strange Hook anomolies and desparate tests to a possible solution

This forum was archived on 2017-11-26.