Understanding the hook system for drupal modules _ drupal. org

A Drupal module is a collection of files containing some functionality and is written in PHP. Database developer Because the module code executes within the context of the site, it can use all the functions and access all variables and structures of Drupal core. Data recovery plan In fact, a module is no different from a regular PHP file that can be independently created and tested and then used to drive multiple functionalities.

This approach allows Drupal core to call at specific places certain functions defined in modules and enhance the functionality of core.


Data recovery kansas city The places where code can be executed are called “hooks” and are defined by a fixed interface. N k database About hooks

Hooks are how modules can interact with the core code of Drupal. Data recovery 2016 They make it possible for a module to define new urls and pages within the site (hook_menu), to add content to pages (hook_block, hook_footer, etc.), to set up custom database tables (hook_schema) and more. 510 k database fda This page lists the hooks provided in the core, but modules can define hooks of their own. Database programmer For example, the cck module defines hook_field_info, which can be used by modules that want to define a new type of content field. Data recovery osx Most modules that define hooks will also provide documentation about them.

Hooks occur at various points in the thread of execution, where Drupal seeks contributions from all the enabled modules. Database integrity For example, when a user visits a help page on a Drupal site, as Drupal builds the help page it will give each module a chance to contribute documentation about itself. Database backup It does this by scanning all the module code for functions that have the name mymodule_help($path, $arg), where “mymodule” is the module’s name, e.g., the block module’s help hook is called block_help and the node module’s help hook is called node_help. Hollywood u database The hook may provide parameters; hook_help’s parameters $path and $arg allow the developer to determine what page or pages the help messages will appear on.

A hook can be thought of as an event listener in the sense that an event triggers an action. Data recovery ipad The event in Drupal, such as deleting a node, would trigger the hook “hook_delete”. Database vs server If your module implemented hook_delete, that function would run when a node deletion occurred. Database is in transition As an example, your function might be to decrease the count of the total number of nodes, so when a node was deleted, your function would be called and lower the count by 1.

See also the overview of module hooks, in the Drupal API Reference. Data recovery ios You might want to check out also this good article discussing how Drupal module/hook system works, using simple PHP constructs/snippets.

banner