User login

Drupal Hooks: A Brief Introduction

Hooks in Drupal are a way of triggering code to run based on naming convention.

This simple and powerful system is a key way in which you or other developers can extend Drupal.

http://api.drupal.org/api/group/hooks/7

Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.

Hooks in D7 have undergone a process of de-opping, meaning that where one hook was called multiple times in different contexts (by way of different 'op' values being passed in), now a separate hook runs for each case. (This may be less convenient in certain cases, but overall it is a major win for the coding experience.

Searched words: 
hook hooking hookey hooks

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.