Skip to content
Snippets Groups Projects
Commit ad96fe93 authored by Sean Madsen's avatar Sean Madsen
Browse files

hook_civicrm_post - basic cleaning after import.

fixes #84
parent f09e3c2c
No related branches found
No related tags found
No related merge requests found
......@@ -12,25 +12,21 @@ deleted first).
## Definition
hook_civicrm_post($op, $objectName, $objectId, &$objectRef)
```php
hook_civicrm_post($op, $objectName, $objectId, &$objectRef)
```
## Parameters
- $op - operation being performed with CiviCRM object. Can have the
following values:
- `$op` - operation being performed with CiviCRM object. Can have the following values:
- 'view' : The CiviCRM object is going to be displayed
- 'create' : The CiviCRM object is created (or contacts are being
added to a group)
- 'create' : The CiviCRM object is created (or contacts are being added to a group)
- 'edit' : The CiviCRM object is edited
- 'delete' : The CiviCRM object is being deleted (or contacts are
being removed from a group)
- 'trash': The contact is being moved to trash (Contact objects
only)
- 'delete' : The CiviCRM object is being deleted (or contacts are being removed from a group)
- 'trash': The contact is being moved to trash (Contact objects only)
- 'restore': The contact is being restored from trash (Contact objects only)
- 'restore': The contact is being restored from trash (Contact
objects only)
- $objectName - can have the following values:
- `$objectName` - can have the following values:
- 'Activity'
- 'Address'
- 'Case'
......@@ -59,19 +55,17 @@ deleted first).
- 'Phone'
- 'Pledge'
- 'PledgePayment'
- 'Profile' (while this is not really an object, people have
- 'Profile' *(while this is not really an object, people have
expressed an interest to perform an action when a profile is
created/edited)
created/edited)*
- 'Relationship'
- 'Tag'
- 'UFMatch' (when an object is linked to a CMS user record, at the
- 'UFMatch' *(when an object is linked to a CMS user record, at the
request of GordonH. A UFMatch object is passed for both the pre
and post hooks)
and post hooks)*
- $objectId - the unique identifier for the object. tagID in case of
EntityTag
- $objectRef - the reference to the object if available. For case of
EntityTag it is an array of (entityTable, entityIDs)
- `$objectId` - the unique identifier for the object. `tagID` in case of `EntityTag`
- `$objectRef` - the reference to the object if available. For case of `EntityTag` it is an array of (`entityTable`, `entityIDs`)
## Returns
......@@ -80,67 +74,66 @@ deleted first).
## Example
Here is a simple example that will send you an email whenever an
INDIVIDUAL Contact is either Added, Updated or Deleted:
individual contact is either added, updated or deleted:
Create a new folder called example_sendEmailOnIndividual in this
Create a new folder called `example_sendEmailOnIndividual` in this
directory
/drupal_install_dir/sites/all/modules/civicrm/drupal/modules/ and then
`/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.
".$op." ".$objectName."
".$objectId." ";
if ($op == 'create' && $objectName == 'Individual') {
$email_sbj .= "- ADDED NEW contact";
$email_msg .= $objectRef->display_name."
";
$send_an_email = true;
} else if ($op == 'edit' && $objectName == 'Individual') {
$email_sbj .= "- EDITED contact";
$email_msg .= $objectRef->display_name."
";
$send_an_email = true;
} else if ($op == 'delete' && $objectName == 'Individual') {
$email_sbj .= "- DELETED contact";
$email_msg .= $objectRef->display_name."
";
$email_msg .= 'Phone: '.$objectRef->phone."
";
$email_msg .= 'Email: '.$objectRef->email."
";
$send_an_email = true;
}
if ($send_an_email) {
mail($email_to, $email_sbj, $email_msg, "From: ".$email_from);
}
}//end FUNCTION
?>
File 1:
`/drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.info`
```txt
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
<?php
function exampleSendEmailOnIndividual_civicrm_post($op, $objectName, $objectId, &$objectRef) {
$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);
}
}
```
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!
\ No newline at end of file
a contact and you should get an email!
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment