Skip to content
Snippets Groups Projects
Commit 88043d62 authored by Sean Madsen's avatar Sean Madsen Committed by GitHub
Browse files

Merge pull request #114 from mickadoo/master

Update hooks page
parents 43532d62 42413589
Branches
No related tags found
No related merge requests found
site
\ No newline at end of file
This diff is collapsed.
......@@ -3,7 +3,9 @@
## Description
This hook is called when an extension is uninstalled. To be specific,
when its status changes from ***disabled*** to ***uninstalled******.***
when its status changes from ***disabled*** to ***uninstalled***.
Each module will receive hook_civicrm_uninstall during its own
uninstallation (but not during the uninstallation of unrelated modules).
......
## Using hooks with Drupal
The Drupal documentation has good information about
[hooks in general](https://www.drupal.org/docs/7/creating-custom-modules/understanding-the-hook-system-for-drupal-modules)
and [configuration to enable hooks for your module](https://www.drupal.org/docs/7/creating-custom-modules/telling-drupal-about-your-module)
In order to start using hooks with a Drupal-based CiviCRM installation, you or
your administrator needs to do the following:
1. Create a file with the extension .info (for instance, myhooks.info)
containing the following lines. Replace the example text in the first 2
lines with something appropriate for your organization, and assign 7.x
to core if you use Drupal 7.
name = My Organization's Hooks
description = Module containing the CiviCRM hooks for my organization
dependencies[] = civicrm
package = CiviCRM
core = 7.x
version = 7.x-1.0
2. Create a new file with the extension *.module* (for instance,
*myhooks.module*) to hold your PHP functions.
3. Upload both the *.info* and *.module* files to the server running CiviCRM,
creating a new directory for them under */sites/all/modules* (for
instance, */sites/all/modules/myhooks/*) inside your Drupal installation.
The directory name you create should be short and contain only lowercase
letters, digits, and underlines without spaces.
4. Enable your new hooks module through the Drupal administration page.
Additionally, if you are using Drupal and add a new hook to an existing module,
you will need to clear the cache for the hook to start operating. One way of
doing this is by visiting the page Admin > Build > Modules.
Note that if you use certain Drupal functions from within CiviCRM, you could
break whatever form you're working with! To prevent very hard-to-troubleshoot
errors, do the following (at least for `user_save()` with Drupal 6, possibly
others):
```php
$config = CRM_Core_Config::singleton();
```
```php
$config->inCiviCRM = TRUE;
```
```php
$user = user_save('',array(..));
```
```php
$config->inCiviCRM = FALSE;
```
\ No newline at end of file
## Using hooks with Joomla!
Hooks may be implemented in Joomla in two ways, depending on the version of
CiviCRM and Joomla you are using. For sites running Joomla 1.5 with CiviCRM up
to and including version 3.4, you implement hooks with a single civicrmHooks.php
in your php override directory. Sites running Joomla 1.6+ and CiviCRM 4+ may
implement with either that single hooks file, or by creating a Joomla plugin.
In general, implementing through a plugin is preferred as you can benefit from
the native access control within the plugin structure, include code that
responds to other Joomla events, organize your hook implementations into
multiple plugins which may be enabled/disabled as desired, and roughly follow
the event-observer pattern intended by Joomla plugins.
As you implement hooks in Joomla, be sure to check the CiviCRM wiki for the
most up-to-date information:
- [http://tiny.booki.cc/?hooks-in-joomla](http://tiny.booki.cc/?hooks-in-joomla)
- [http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification\#CiviCRMhookspecification-Proceduresforimplementinghooks%28forJoomla%29](http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-Proceduresforimplementinghooks%28forJoomla%29)
To implement hooks with a single file, you will do the following:
1. If you have not done so already, create a new directory on your server to
store your PHP override files. In Joomla, that is commonly placed in the
media folder, as it will not be impacted by Joomla and CiviCRM upgrades.
For example, you might create the following
folder: `/var/www/media/civicrm/customphp`.
2. If you have not done so already, configure your system to reference the
folder you've created as your override directory. Go to: CiviCRM
Administer > Global Settings > Directories. Change the value of Custom
PHP Path Directory to the absolute path for the new directory (e.g.,
"/var/www/media/civicrm/customphp" if you used that suggestion in the
earlier step). The custom override directory may also be used to store
modified copies of core files -- thus overriding them. You may want to
familiarize yourself with its purpose if you are not yet.
3. Create a file named *civicrmHooks.php* to contain your hook
implementations, and upload the file to the directory you just created.
4. Within that file, your hooks will be implemented by calling the hook
function prefaced by "joomla\_". For example, you would call the buildForm
hook (used to modify form rendering and functionality) by adding the
following function to your hook file:
```php
function joomla_civicrm_buildForm( $formName, &$form ) {
//your custom code
}
```
If you are implementing hooks with a Joomla plugin, you will create a standard,
installable plugin package. At a minimum, a plugin extension will consist of an
xml file (defining the plugin and its parameters), and a php file. Within the
php file, define a class that extends the Joomla JPlugin class, and call your
hooks but adding the appropriate functions. For example, your plugin file may
look like the following:
```
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgCiviCRMMyPlugin extends JPlugin {
public function civicrm_tabs(&$tabs, $contactID) {
//your code to alter the contact summary tabs
}
}
```
The first two lines are required -- the first is for security purposes, and
ensures the code will exit if it has not been called from within Joomla. The
second includes the necessary parent plugin class.
Joomla plugin classes follow standard naming conventions which you should
follow. By naming this plugin class "plgCiviCRMMyPlugin," I am stating that the
plugin resides in the plugin/civicrm/ folder, and the plugin file is named
"myplugin.php."
For more information about implementing hooks through plugins, see this [blog
article](http://civicrm.org/blogs/mcsmom/hooks-and-joomla)
Note the reference in the comments to a sample plugin which you can download
and modify.
......@@ -73,6 +73,9 @@ pages:
# API Changes: api/changes.md # page-tree = NEED_NEW_PAGE
- Hooks:
- Using hooks: hooks.md # page-tree = NEED_PAGE_MOVE to /hooks/usage.md
- Setup:
- Hooks with Joomla: hooks/setup/joomla.md
- Hooks with Drupal: hooks/setup/drupal.md
- Batch hooks:
- hook_civicrm_batchItems: hooks/hook_civicrm_batchItems.md
- hook_civicrm_batchQuery: hooks/hook_civicrm_batchQuery.md
......
......@@ -110,4 +110,5 @@ hook_civicrm_searchProfile hooks/hook_civicrm_searchProfile
hook_civicrm_validateProfile hooks/hook_civicrm_validateProfile
hook_civicrm_viewProfile hooks/hook_civicrm_viewProfile
hook_civicrm_alterReportVar hooks/hook_civicrm_alterReportVar
Hook+Reference hooks
Hooks hooks
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment