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) »
  • Can't get hooks to work with civiCRM 4
Pages: [1]

Author Topic: Can't get hooks to work with civiCRM 4  (Read 1466 times)

tac12

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.3.5
  • CMS version: Drupal6
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Can't get hooks to work with civiCRM 4
April 27, 2011, 12:26:04 pm
After extensive RTFM I must be missing something.  Have tried the send email example on individual create/edit on both a joomla 1.6/civi4 and drupal7/civi4. Both clean new installs on top of Centos.  Yes I have checked the emails are working. No emails going out. None of the other examples seem to do anything either, eg the network login example. What have  I missed?

theMusician

  • I post occasionally
  • **
  • Posts: 48
  • Karma: 3
  • CiviCRM version: 4.0 and 4.0.1
  • CMS version: Drupal 7.0
  • MySQL version: MySQL 5.x
  • PHP version: 5.2
Re: Can't get hooks to work with civiCRM 4
April 27, 2011, 12:54:01 pm
What hook are trying to use? I can confirm that creating a custom module and pulling data from custom_data tables works properly. Keep at it, it can be frustrating at first.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Can't get hooks to work with civiCRM 4
April 27, 2011, 01:15:07 pm
Can you post your code? Can you confirm that your module is registered correctly and enabled in Drupal?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

tac12

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.3.5
  • CMS version: Drupal6
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Re: Can't get hooks to work with civiCRM 4
April 27, 2011, 02:41:14 pm
Module registered and enabled,  code is taken directly from the developer section of the online documentation:

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification

I started out using Joomla,  when I couldnt get hooks to work I gave drupal a go,

I used the example code for hook_civicrm_post:

Here is a simple example that will send you an email whenever an INDIVIDUAL Contact is either Added, Updated or Deleted:

Create a new folder called example_sendEmailOnIndividual in this directory /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/ and then put the following two files in that directory (change the email addresses to yours).

FILE #1 /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.info
name = Example Send Email On Individual
description = Example that will send an email when an Individual Contact is Added, Updated or Deleted.
dependencies[] = civicrm
package = CiviCRM
core = 6.x
version = 1.0
FILE #2 /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.module
 <?php
function exampleSendEmailOnIndividual_civicrm_post($op, $objectName, $objectId, &$objectRef) {

  /**************************************************************
   * Send an email when Individual Contact is CREATED or EDITED or DELETED
   */
  $send_an_email = false; //Set to TRUE for DEBUG only
  $email_to = 'me@mydomain.com'; //TO email address
  $email_from = 'me@mydomain.com'; //FROM email address
  $email_sbj = 'CiviCRM exampleSendEmailOnIndividual';
  $email_msg = "CiviCRM exampleSendEmailOnIndividual was called.\n".$op." ".$objectName."\n".$objectId." ";

  if ($op == 'create' && $objectName == 'Individual') {
    $email_sbj .= "- ADDED NEW contact";
    $email_msg .= $objectRef->display_name."\n";
    $send_an_email = true;
  } else if ($op == 'edit' && $objectName == 'Individual') {
    $email_sbj .= "- EDITED contact";
    $email_msg .= $objectRef->display_name."\n";
    $send_an_email = true;
  } else if ($op == 'delete' && $objectName == 'Individual') {
    $email_sbj .= "- DELETED contact";
    $email_msg .= $objectRef->display_name."\n";
    $email_msg .= 'Phone: '.$objectRef->phone."\n";
    $email_msg .= 'Email: '.$objectRef->email."\n";
    $send_an_email = true;
  }

  if ($send_an_email) {
    mail($email_to, $email_sbj, $email_msg, "From: ".$email_from);
  }

}//end FUNCTION
?>
Once the files are in the directory, you need to login to Drupal admin, go to Modules and enable our new module and click Save. Now go and edit a contact and you should get an email!

Of course I changed the e-mail addresses,  and I am monitoring the mail server on the webhost (centos in a VM).


tac12

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.3.5
  • CMS version: Drupal6
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Re: Can't get hooks to work with civiCRM 4
April 28, 2011, 01:50:10 am
Well I've managed to get the network login ID example  to work on Drupal7/Civi4,  not sure what I did differently!  Keeping at it seems to be the order of the day!


Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Can't get hooks to work with civiCRM 4
April 28, 2011, 01:53:18 am
Glad to hear. Let us know if we can help with anything else.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Can't get hooks to work with civiCRM 4
April 28, 2011, 05:08:07 am
Quote from: tac12 on April 27, 2011, 02:41:14 pm
Module registered and enabled,  code is taken directly from the developer section of the online documentation:

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification
FILE #1 /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.info
name = Example Send Email On Individual
description = Example that will send an email when an Individual Contact is Added, Updated or Deleted.
dependencies[] = civicrm
package = CiviCRM
core = 6.x
version = 1.0

One thing jumps out immediately, which is that the example code is designed to tell Drupal that this module is only compatible with Drupal 6. I don't believe that quotation marks around the description are required, but it is usual. Reference: http://drupal.org/node/542202
So try:
Code: [Select]
description = "Example that will send an email when an Individual Contact is Added, Updated or Deleted."
dependencies[] = civicrm
package = CiviCRM
core = 7.x
version = 1.0
Lead Developer, C3 Design.
Twitter: @FatherShawn

tac12

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.3.5
  • CMS version: Drupal6
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Re: Can't get hooks to work with civiCRM 4
May 04, 2011, 07:46:07 am
Well the good news is that I have done what I set out to do, namely using hooks to link a junior player with their parent,  set the relationship and allow the parent to edit the child,  however only  with Drupal7/civiCRM4.  Exactly the same code (apart from making the function joomla_civicrm_post{} pasted into customHooks.php does absolutely nothing on Joomla 1.6/CiviCRM4

Whilst its not a disaster using Drupal,  it would be quite nice to get the hook to work in Joomla.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Can't get hooks to work with civiCRM 4
May 04, 2011, 07:59:36 am
I would suggest you post your code in a fresh thread.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Can't get hooks to work with civiCRM 4
May 04, 2011, 08:08:40 am
Hi,

Check the book, the syntax for a joomla hook is slightly different than for drupal.

http://en.flossmanuals.net/civicrm/ch067_hooks/
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

tac12

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 4.3.5
  • CMS version: Drupal6
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Re: Can't get hooks to work with civiCRM 4
May 05, 2011, 11:31:16 pm
Yes, I've read that, and followed the instructions.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Can't get hooks to work with civiCRM 4

This forum was archived on 2017-11-26.