Last updated February 19, 2008. Created by Dries on May 30, 2005.
Edited by puregin, ax. Log in to edit this page.

Hook changes

Other than those mentioned above, the following hooks have changed:

  • The _view hook has been changed to return its content rather than printing it. It also has an extra parameter, $page, that indicates whether the node is being viewed as a standalone page or as part of a larger context. This is important because nodes may change the breadcrumb trail if they are being viewed as a page. Old usage:
    <?php
    function example_view($node, $main = 0) {
      if (
    $main) {
       
    theme("node", $node, $main);
      }
      else {
       
    $breadcrumb[] = l(t("Home"), "");
       
    $breadcrumb[] = l(t("foo"), "foo");
       
    $node->body = theme("breadcrumb", $breadcrumb) ."<br />". $node->body;
       
    theme("node", $node, $main);
      }
    }
    ?>

    New usage:
    <?php
    function example_view($node, $main = 0, $page = 0) {
      if (
    $main) {
        return
    theme("node", $node, $main, $page);
      }
      else {
        if (
    $page) {
         
    $breadcrumb[] = l(t("Home"), "");
         
    $breadcrumb[] = l(t("foo"), "foo");
         
    drupal_set_breadcrumb($breadcrumb);
        }
        return
    theme("node", $node, $main, $page);
      }
    }
    ?>
  • The _form hook used by node modules does no longer take 3 arguments. The second argument $help, typically used to print submission guidelines, has been removed. Instead, the help should be emitted using the module's _help hook. For examples, check the story, forum or blog module.
  • The _search hook was changed to not only return the result set array, but a two element array with the result group title and the result set array. This provides more precise control over result group titles.
  • The _head hook is eliminated and replaced with the drupal_set_html_head() and drupal_get_html_head() functions. You can add JavaScript code or CSS to the HTML head part with the drupal_set_html_head() function instead.
  • See also the description of the _compose_tips hook changes below.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.