Friday 11 March 2011

How to create your own hook in drupal

Today I will show you how you can create your own module hook in drupal 7 that is so easy to do
First you must create a api file for the module which you wanna create a hook

YOUR_MODULE_NAME.api.php

create hook method in this file

function hook_YOUR_MODULE_NAME_item_update($item) {

//nothing defined here

}

then in your module file create a method which update data for item

YOUR_MODULE_NAME.module

function YOUR_MODULE_NAME_item_update() {

//your code to update

module_invoke_all('MODULE_NAME_item_update', $item);

}

in orther module you can create function to implement this method

NEW_MODULE.module

function NEW_MODULE_item_update($item) {

//do something with item

}


1 comment:

  1. Is this code is applicable to create schema hook for database?

    ReplyDelete