• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

Userpoints Meter

0 Points /1000 Points

Drupal hook

  • Drupal hook: hook_comment

    hook_comment lets you operate on comments that is being operated upon. You can perform actions on comments by using this hook. For example, after certain number of commnets reached, you want to hide certain number of comments just like the way facebook does. You can use hook_commentk and theme the output as per your requirements.
    Syntax:
    Drupal 5.x - 6.x: hook_comment($a1, $op)
    $a1: when $op is either 'validate', 'insert' or 'update', this holds the foprm submmitted values.
    When you are editing the comment from comment/edit/*, $a1 will be an array, in rest of the cases, it will be an object.
    $op: $op is every thing that can be performed on a comment. like
    'insert',
    'update',
    'validate',
    'publish',
    'delete',
    'view'.

  • Drupal hook: hook_link

    hook_link lets us define links to be displayed on nodes and comments. These are the links wich makes it easy for the end user to access more information related to a node. Like adding comment, accessing the tags and sending feedback to node authors or site admin using
    http://ly2.in/B]EGD_ module. The node feedback module adds a link on nodes which lets the users to contact the node author or the site admin.

    hook_link parametes

    • $type: The type of the links placed either below the comments or nodes
    • $object: Since this hook serves both comments and node equally, its an $object rather than just a $node.
    • $teaser: This is a boolean value. It indicates what form of node is currently being displayed. You can display the links accordingly.
  • Drupal hook: hook_user

    Drupal offers user management out of the box. This includes new user registration, log in, password mailer and user session management. Drupal stores password as md5 hash value. When a user provides her log in credentials, Drupal generates md5 has values for the password provided and compares it with the one stored in the database against the provided username/email address. This is a well known technique implemented by Unix.

  • Drupal hook: hook_user

    Drupal offers user management out of the box. This includes new user registration, log in, password mailer and user session management. Drupal stores password as md5 hash value. When a user provides her log in credentials, Drupal generates md5 has values for the password provided and compares it with the one stored in the database against the provided username/email address. This is a well known technique implemented by Unix.

  • Drupal hook: hook_mail_alter

    When sending e-mails or newsletters from your website, you might want to inject some information like website name, disclaimer, copy right information, unsubscribe link and such. Just like hook_form_alter, you can use hook_mail_alter to virtually alter anything in the mail just before Drupal sends the e-mail. You can even change the mime type of the email, for example, from plain text to HTML and vice versa.
    Here is the syntax/signature of the hook

    • Drupal 5: hook_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers)
    • Drupal 6, 7: hook_mail_alter(&$message)

    $message has the following key-value pairs:

    • 'id': Unique id of the mail being sent.
    • 'to': The destination e-mail address(es)
  • Drupal hook: hook_view

    The full view of a node including all the information associated with the nodes like author, node posted date, file attached to the node and any other data that are associated by other custom modules is managed by hook_view. The main goal and use of the hook_view is to allow the node modules to add extra information and manage those extra information to display when viewing the node. Nodes can have tease view as well as page view. On teaser view, only some of the information associated with the node is displayed; we can say its an overview of the node. On page view, all the information associated with the node is displayed.

    <?php
    /**
    * Implementation of hook_view
    * @param $node
    * @param $teaser
    * @param $page
    * @return unknown_type
    * @author Drupal Developer
    */

  • Drupal hook: hook_block

    Blocks are the one of the basic and most fascinating features of Drupal. With block you can display information in the form of block by saving and utilizing the screen area. Here is an example of implementation of hook_block

    <?php
    /**
    * Implementation of hook_block
    *
    * @param $op
    * @param $delta
    * @param $edit
    * @return $block
    * @author Drupal Developer
    */
    function browse_info_block($op = 'list', $delta = 0, $edit = array()) {
    switch ($op) {
    case 'list':
    $blocks[1] = array(
    'info' => t("Browse information by category"),
    'status' => 1,
    'region' => 'content',
    'weight' => 0,
    );

    return $blocks;
    case 'configure':
    switch($delta) {
    case 1:
    $am__vocabulary = _get_vocabulary();

  • Drupal hook: hook_cron

    You've just published a Drupal website and people find it very useful. So, they started signing up with your website and its really very good traffic now. You have planned to implement some features and you want to let know about to all the members of the site. There are two ways: you send e-mails to individuals by using their contact form or implement a system with which you create a node and the site itself sends e-mails. How about sending the e-mails at specific period of time? ohh.. yeah. that's great. Drupal's hook_run makes it happen. Since, there are more features to come, you want to do this every time you have something new to let others know about, you would use hook_cron, which performs specific tasks assigned to it periodically.

  • Drupal hook: hook_install

    hook_install() creates tables in the database for the module to which its associated. hook_install not just restricted creating tables but it also creates vocabularies, terms in the vocabularies and sets variables to be used by modules. The hook_install set ups the basic requirement for a module to function properly. Not all the modules require to implement hook_install but which saves data to own tables and for providing extra features for which there are no tables or fields exists from where information can be fetched.

    • Drupal 5: Table definition and all other required set up for the module
    • Drupal 6, 7: drupal_install_schema('[hook]')

    Here is an example of hook_install()

    <?php
    /**
    * Implementation of hook_install
    *

  • Drupal Module hooks : Module file

Syndicate content

Recent comments