Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
brienne
Developer Documentation
Commits
ad96fe93
Commit
ad96fe93
authored
8 years ago
by
Sean Madsen
Browse files
Options
Downloads
Patches
Plain Diff
hook_civicrm_post - basic cleaning after import.
fixes #84
parent
f09e3c2c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/hooks/hook_civicrm_post.md
+70
-77
70 additions, 77 deletions
docs/hooks/hook_civicrm_post.md
with
70 additions
and
77 deletions
docs/hooks/hook_civicrm_post.md
+
70
−
77
View file @
ad96fe93
...
@@ -12,25 +12,21 @@ deleted first).
...
@@ -12,25 +12,21 @@ deleted first).
## Definition
## Definition
hook_civicrm_post($op, $objectName, $objectId, &$objectRef)
```
php
hook_civicrm_post
(
$op
,
$objectName
,
$objectId
,
&
$objectRef
)
```
## Parameters
## Parameters
-
$op - operation being performed with CiviCRM object. Can have the
-
`$op`
- operation being performed with CiviCRM object. Can have the following values:
following values:
-
'view' : The CiviCRM object is going to be displayed
-
'view' : The CiviCRM object is going to be displayed
-
'create' : The CiviCRM object is created (or contacts are being
-
'create' : The CiviCRM object is created (or contacts are being added to a group)
added to a group)
-
'edit' : The CiviCRM object is edited
-
'edit' : The CiviCRM object is edited
-
'delete' : The CiviCRM object is being deleted (or contacts are
-
'delete' : The CiviCRM object is being deleted (or contacts are being removed from a group)
being removed from a group)
-
'trash': The contact is being moved to trash (Contact objects only)
-
'trash': The contact is being moved to trash (Contact objects
-
'restore': The contact is being restored from trash (Contact objects only)
only)
- 'restore': The contact is being restored from trash (Contact
-
`$objectName`
- can have the following values:
objects only)
-
$objectName - can have the following values:
-
'Activity'
-
'Activity'
-
'Address'
-
'Address'
-
'Case'
-
'Case'
...
@@ -59,19 +55,17 @@ deleted first).
...
@@ -59,19 +55,17 @@ deleted first).
-
'Phone'
-
'Phone'
-
'Pledge'
-
'Pledge'
-
'PledgePayment'
-
'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
expressed an interest to perform an action when a profile is
created/edited)
created/edited)
*
-
'Relationship'
-
'Relationship'
-
'Tag'
-
'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
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
-
`$objectId`
- the unique identifier for the object.
`tagID`
in case of
`EntityTag`
EntityTag
-
`$objectRef`
- the reference to the object if available. For case of
`EntityTag`
it is an array of (
`entityTable`
,
`entityIDs`
)
-
$objectRef - the reference to the object if available. For case of
EntityTag it is an array of (entityTable, entityIDs)
## Returns
## Returns
...
@@ -80,67 +74,66 @@ deleted first).
...
@@ -80,67 +74,66 @@ deleted first).
## Example
## Example
Here is a simple example that will send you an email whenever an
Here is a simple example that will send you an email whenever an
INDIVIDUAL C
ontact is either
A
dded,
U
pdated or
D
eleted:
individual c
ontact is either
a
dded,
u
pdated or
d
eleted:
Create a new folder called example_sendEmailOnIndividual in this
Create a new folder called
`
example_sendEmailOnIndividual
`
in this
directory
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
put the following two files in that directory (change the email
addresses to yours).
addresses to yours).
FILE #1 /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.info
File 1:
name = Example Send Email On Individual
`/drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.info`
description = Example that will send an email when an Individual Contact is Added, Updated or Deleted.
dependencies[] = civicrm
```
txt
package = CiviCRM
name = Example Send Email On Individual
core = 6.x
description = Example that will send an email when an Individual Contact is Added, Updated or Deleted.
version = 1.0
dependencies[] = civicrm
package = CiviCRM
FILE #2 /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.module
core = 6.x
version = 1.0
<?php
```
function exampleSendEmailOnIndividual_civicrm_post($op, $objectName, $objectId, &$objectRef) {
File 2:
/**************************************************************
* Send an email when Individual Contact is CREATED or EDITED or DELETED
`/drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sendEmailOnIndividual/example_sendEmailOnIndividual.module`
*/
$send_an_email = false; //Set to TRUE for DEBUG only
```
php
$email_to = 'me@mydomain.com'; //TO email address
<?php
$email_from = 'me@mydomain.com'; //FROM email address
function
exampleSendEmailOnIndividual_civicrm_post
(
$op
,
$objectName
,
$objectId
,
&
$objectRef
)
{
$email_sbj = 'CiviCRM exampleSendEmailOnIndividual';
$email_msg = "CiviCRM exampleSendEmailOnIndividual was called.
$send_an_email
=
false
;
//Set to TRUE for DEBUG only
".$op." ".$objectName."
$email_to
=
'me@mydomain.com'
;
//TO email address
".$objectId." ";
$email_from
=
'me@mydomain.com'
;
//FROM email address
$email_sbj
=
'CiviCRM exampleSendEmailOnIndividual'
;
if ($op == 'create' && $objectName == 'Individual') {
$email_msg
=
"CiviCRM exampleSendEmailOnIndividual was called.
\n
"
.
$op
.
" "
.
$objectName
.
"
\n
"
.
$objectId
.
" "
;
$email_sbj .= "- ADDED NEW contact";
$email_msg .= $objectRef->display_name."
if
(
$op
==
'create'
&&
$objectName
==
'Individual'
)
{
";
$email_sbj
.
=
"- ADDED NEW contact"
;
$send_an_email = true;
$email_msg
.
=
$objectRef
->
display_name
.
"
\n
"
;
} else if ($op == 'edit' && $objectName == 'Individual') {
$send_an_email
=
true
;
$email_sbj .= "- EDITED contact";
}
$email_msg .= $objectRef->display_name."
else
if
(
$op
==
'edit'
&&
$objectName
==
'Individual'
)
{
";
$email_sbj
.
=
"- EDITED contact"
;
$send_an_email = true;
$email_msg
.
=
$objectRef
->
display_name
.
"
\n
"
;
} else if ($op == 'delete' && $objectName == 'Individual') {
$send_an_email
=
true
;
$email_sbj .= "- DELETED contact";
}
$email_msg .= $objectRef->display_name."
else
if
(
$op
==
'delete'
&&
$objectName
==
'Individual'
)
{
";
$email_sbj
.
=
"- DELETED contact"
;
$email_msg .= 'Phone: '.$objectRef->phone."
$email_msg
.
=
$objectRef
->
display_name
.
"
\n
"
;
";
$email_msg
.
=
'Phone: '
.
$objectRef
->
phone
.
"
\n
"
;
$email_msg .= 'Email: '.$objectRef->email."
$email_msg
.
=
'Email: '
.
$objectRef
->
email
.
"
\n
"
;
";
$send_an_email
=
true
;
$send_an_email = true;
}
}
if
(
$send_an_email
)
{
if ($send_an_email) {
mail
(
$email_to
,
$email_sbj
,
$email_msg
,
"From: "
.
$email_from
);
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,
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
go to Modules and enable our new module and click Save. Now go and edit
a contact and you should get an email!
a contact and you should get an email!
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment