Hello,

I'm up to the task of developing my first module which is a quite simple auction module. However, I ran into a problem regarding the different hooks.

As of now, my module is almost complete but most of the hooks that I've implemented are through hook_nodeapi.

For example, in hook_nodeapi, I have

function auction_nodeapi(....) {
    switch ($op) {
        case "load":
            echo "load from nodeapi";
        break;
    }
}

and in hook_load I have

function auction_load(&$node) {
    echo "load from load";
}

However, only the load from nodeapi gets called. This is the same for other operations such as _insert, _update, _validate, etc.
Other hooks work fine, such as _menu, _access...

Has anyone experienced this?

Comments

nevets’s picture

There are two different purpose for hook_nodeapi() and hook_load(), hook_insert(), etc.

hook_nodeapi() is called for any module that implements it for any content type.

hook_load(), hook_insert(), etc are only called for modules that implement a content type and only for the content type(s) the module implements.

marcobaldo’s picture

Yes, my module implements a custom "Auction" content type.

The hook_nodeapi looks something like:

function auction_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
    if ($node->type == "auction") {
        switch ($op) {
            case "load":
              // ....
        }
    }
}

Basically what I'm doing is that I have a custom "Auction" content type -- for now its just as simple as having an Item Name for its title and a CCK Image Field. I already have setup the node types and the necessary install procedures through my own .install file, using content_copy_import_form to import my node type into the database.

For now I just want to print_r out the $node whenever it is loaded.

nevets’s picture

While you have a custom content type it is implemented by CCK, not your module.

marcobaldo’s picture

Edit: I see what you mean now. In the node_types table, my custom node type still derives from 'node' module.
Reading this article, http://www.leveltendesign.com/blog/dustin-currie/drupal-6-node-skeleton, I found the solution.
Thanks!

Isn't it that when you call

drupal_execute('content_copy_import_form', $form_state);

on your hook_install(), the content type that also gets installed is owned and implemented by your own module? At least... that's how I understood it.

Why is it then that if I disable my module, the content type also disappears? Doesn't that mean that my module IS the one owns and is implementing the node type that it created?

nevets’s picture

Your code is still using CCK to implement the content type, it is just using code in place of a person using the UI. Modules that implement content types need to define hook_node_info().