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
1dfe0994
Commit
1dfe0994
authored
8 years ago
by
Sean Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Improving some of the nav structure and page titles to be clearer and more descriptive
parent
49f9d2f9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/hook.md
+2
-7
2 additions, 7 deletions
docs/hook.md
docs/hooks-db.md
+33
-27
33 additions, 27 deletions
docs/hooks-db.md
mkdocs.yml
+25
-25
25 additions, 25 deletions
mkdocs.yml
with
60 additions
and
59 deletions
docs/hook.md
+
2
−
7
View file @
1dfe0994
Hooks
=====
Ho
w to use ho
oks
=====
===========
TODO:
...
...
@@ -27,11 +27,6 @@ A good test for whether or not to use a hook is to ask yourself whether what
you're trying to do can be expressed with a sentence like this: "I want X to
happen every time someone does Y."
How to use hooks
================
How you use hooks depends on whether you're using CiviCRM with Drupal or
Joomla!.
Using hooks with Drupal
-----------------------
...
...
This diff is collapsed.
Click to expand it.
docs/hooks-db.md
+
33
−
27
View file @
1dfe0994
All Available Hooks
===================
This page provides official documentation on the specifics of each hook
available within CiviCRM.
hook_civicrm_copy
=================
This hook is called after a CiviCRM object (Event, ContributionPage, Profile) has been copied
*
Parameters:
*
Parameters:
*
$objectName - the name of the object that is being copied (Event, ContributionPage, UFGroup)
*
$object - reference to the copied object
*
Returns:
*
Returns:
*
null
*
Definition/Example:
*
Definition/Example:
```
hook_civicrm_copy( $objectName, &$object )
```
...
...
@@ -27,7 +33,7 @@ This hook is called AFTER the db write on a custom table
* object $entityID - the entityID of the row in the custom table
* array $params - the parameters that were sent into the calling function
*
Returns:
*
Returns:
*
null - the return value is ignored
*
Definition/Example:
...
...
@@ -36,34 +42,34 @@ This hook is called AFTER the db write on a custom table
/**
* This example generates a custom contact ID (year + number, ex: 20080000001)
*/
function MODULENAME_civicrm_custom( $op, $groupID, $entityID, &$params ) {
if ( $op != 'create' && $op != 'edit' ) {
return;
}
if ($groupID == 1) {
$needs_update = false;
$tableName = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_CustomGroup',
$groupID,
'table_name' );
$sql = "SELECT member_id_4 FROM $tableName WHERE entity_id = $entityID";
$dao = CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
if (! $dao->fetch()) {
$needs_update = true;
}
// Value may also be empty. i.e. delete the value in the interface to reset the field.
if (! $dao->member_id_4) {
$needs_update = true;
}
if ($needs_update) {
$member_id = date('Y') . sprintf('%07d', $entityID);
$sql = "UPDATE $tableName SET member_id_4 = $member_id WHERE entity_id = $entityID";
CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
}
...
...
@@ -98,7 +104,7 @@ For more background, see [API and the Art of Installation](http://civicrm.org/bl
* void - the return value is ignored
*
Definition/Example:
*
Definition/Example:
```
/**
...
...
@@ -144,13 +150,13 @@ The contents of $data will vary based on the $type of data being passed:
*
relTables:
an array of tables used for asking user which elements to merge, as used at civicrm/contact/merge; each table in the array has this format:
`'rel_table_UNIQUE-TABLE-NICKNAME' => array(
'title' => ts('TITLE'),
'tables' => array('TABLE-NAME' [, ...]),
'url' => CRM_Utils_System::url(PATH, QUERY),
)`
*
sqls:
a one-dimensional array of SQL statements to be run in the final merge operation;
These SQL statements are run within a single transaction.
...
...
@@ -180,7 +186,7 @@ hook_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL, $tables = N
* This hook ensures that data in these two tables is included in CiviCRM merge operations.
*/
function civitest_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL ) {
// If you are using Drupal and you use separate DBs for Drupal and CiviCRM, use the following to prefix
// your tables with the name of the Drupal database.
global $db_url;
...
...
@@ -191,7 +197,7 @@ function civitest_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL
else {
$db_default = '';
}
switch ($type) {
case 'relTables':
// Allow user to decide whether or not to merge records in `civitest_foo` table
...
...
@@ -205,14 +211,14 @@ function civitest_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL
// CiviCRM contact ID.
);
break;
case 'cidRefs':
// Add references to civitest_foo.contact_id, and civitest_foo.foo_id, both of which
// are foreign keys to civicrm_contact.id. By adding this to $data, records in this
// table will be automatically included in the merge.
$data[$db_default . 'civitest_foo'] = array('contact_id', 'foo_id');
break;
case 'eidRefs':
// Add references to civitest_bar table, which is keyed to civicrm_contact.id
// using `bar_entity_id` column, when `entity_table` is equal to 'civicrm_contact'. By
...
...
@@ -220,7 +226,7 @@ function civitest_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL
// the merge.
$data[$db_default . 'civitest_bar'] = array('entity_table' => 'bar_entity_id');
break;
case 'sqls':
// Note that this hook can be called twice with $type = 'sqls': once with $tables
// and once without. In our case, SQL statements related to table `civitest_foo`
...
...
@@ -236,7 +242,7 @@ function civitest_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL
// modify existing SQL statements in $data.
}
break;
}
}
...
...
@@ -323,7 +329,7 @@ FILE #2 /drupal_install_dir/sites/all/modules/civicrm/drupal/modules/example_sen
```
<?php
function
exampleSendEmailOnIndividual_civicrm_post
(
$op
,
$objectName
,
$objectId
,
&
$objectRef
)
{
/**************************************************************
* Send an email when Individual Contact is CREATED or EDITED or DELETED
*/
...
...
@@ -332,7 +338,7 @@ function exampleSendEmailOnIndividual_civicrm_post($op, $objectName, $objectId,
$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
"
;
...
...
@@ -348,11 +354,11 @@ function exampleSendEmailOnIndividual_civicrm_post($op, $objectName, $objectId,
$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
?>
```
...
...
@@ -376,7 +382,7 @@ hook_civicrm_postSave_[table_name]($dao)
```
hook_civicrm_postSave_civicrm_contact($dao) {
$contact_id = $dao->id;
// Do something with this contact, but be careful not to create an infinite
// Do something with this contact, but be careful not to create an infinite
// loop if you update it via the api! This hook will get called again with every update.
}
```
...
...
@@ -516,7 +522,7 @@ function regionfields_civicrm_triggerInfo(&$info, $tableName) {
if(civicrm_api3('custom_field', 'getcount', array('id' => $customFieldID, 'column_name' => 'region_45', 'is_active' => 1)) == 0) {
return;
}
$sql = "
REPLACE INTO `$table_name` (entity_id, $columnName)
SELECT * FROM (
...
...
This diff is collapsed.
Click to expand it.
mkdocs.yml
+
25
−
25
View file @
1dfe0994
site_name
:
CiviCRM Developer Documentation
repo_url
:
https://github.com/civicrm/civicrm-dev-docs
site_description
:
'
A
guide
for
CiviCRM
developers.
'
site_author
:
'
The
CiviCRM
community
'
site_description
:
A guide for CiviCRM developers.
site_author
:
The CiviCRM community
theme
:
readthedocs
pages
:
-
Home
:
index.md
-
Guide
:
-
Requirements
:
requirements.md
-
Build
:
build.md
-
Customize
:
customize.md
-
Extend
:
extend.md
-
Develop
:
develop.md
-
Git
:
git.md
-
Testing
:
testing.md
-
Writing Documentation
:
documentation.md
-
'
Reference:
APIv3
'
:
-
General
:
api/general.md
-
'
Usage
'
:
api/usage.md
-
Actions
:
api/actions.md
-
Parameters
:
api/params.md
-
Chaining
:
api/chaining.md
-
'
Reference:
Hooks
'
:
-
General
:
hook.md
-
Database
:
hooks-db.md
-
Miscellaneous
:
-
'
Extension
Lifecycle
'
:
extend-stages.md
-
Home
:
index.md
-
Guide
:
-
Requirements
:
requirements.md
-
Build
:
build.md
-
Customize
:
customize.md
-
Extend
:
extend.md
-
Develop
:
develop.md
-
Git
:
git.md
-
Testing
:
testing.md
-
Writing Documentation
:
documentation.md
-
APIv3
:
-
API Intro
:
api/general.md
-
API
Usage
:
api/usage.md
-
API
Actions
:
api/actions.md
-
API
Parameters
:
api/params.md
-
API
Chaining
:
api/chaining.md
-
Hooks
:
-
How to Use Hooks
:
hook.md
-
All Available Hooks
:
hooks-db.md
-
Miscellaneous
:
-
Extension Lifecycle
:
extend-stages.md
-
Markdown
:
markdownrules.md
-
hookref-old
:
hookref-old.md
-
Deprecated
:
-
'
Building
CiviCRM
from
source
'
:
develop-deprecated.md
-
Deprecated
:
-
Building CiviCRM from source
:
develop-deprecated.md
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