I've based a module around this excellent example. It would be more correct to say that I've taken the example and changed the names and added a few things. One thing that has me puzzled, is that when I install my module it appears on the node/add page until I clear the cache. Then it disappears!

I've 'solved' the problem by including an implementation of 'hook_info' in my module, but I don't know how the node_example module gets away with not having such an implementation! I'd love to know.

Comments

ilo’s picture

Sorry, do you mean hook_node_info() ?

If this is the case then there is a little literature about it:
#942830: Missing hook_node_info() in node_example.module
#902740: Dont use hook_node_info

Not sure what is the expected behavior here.. perhaps we should fill a core bug?

cliffp’s picture

Hi ilo, yes I did mean hook_node-info(). I located a D6 issue which describes the problem (or a problem with similar symptoms) : http://drupal.org/node/960922. He found the solution at http://drupal.org/node/982270, where he was advised to move his hook_node_info from his .install to his .module. I created a hook_node_info implementation and my new 'content type' stayed in node/add after a cache clear.

The interesting thing is that node_example doesn't have a hook_node_info implementation and yet the node_example content type stays in node/add after a cache clear, and I thought that my module was pretty much a clone of node_example. It was a clone to begin with.

I looked at the references but I don't really understand them and they seem to refer to other stuff. I'll need to digest http://drupal.org/node/755640 which is where all the action seems to be.

Cheers,

Cliff

cliffp’s picture

BTW, as I'm new to this, how do you create the pink and blue links above?

rfay’s picture

@cliffp, there is a filter that parses issues. You use text like this:

#942830: Missing hook_node_info() in node_example.module becomes #942830: Missing hook_node_info() in node_example.module

You can point to a particular comment in an issue with #902740-3: Dont use hook_node_info Like this: #902740-3: Dont use hook_node_info

The colors indicate the state the issue is in. You can also float over to see what the color means.

mile23’s picture

@cliffp, hook_node_info() is a way for your module to define a node in the old-school NodeAPI system. You can see it in action in the Drupal 6 node_example.module.

In Drupal 7, you do basically the same thing but using node_type_save() and 'base' => 'node_content' in hook_install(), which you can see in node_example.install. Drupal 7 also supports the NodeApI system (upgraded in a few ways), but node_type_save() is the new best practice.

cliffp’s picture

SOLVED ----

I'm still not quite sure what is going on, but Mile23 solved it for me! Mile23, I know that hook_node_info is the D6 way of doing it, and that is why I have pursued the issue. I already used node_type_save(), but what I had wrong was that I had set 'base' to 'mymodule' and not 'node_content'.

At last I can move on!

Thank you, thank you, thank you!

Cliff

cliffp’s picture

@rfay,

Thanks for the info,

Cliff

rfay’s picture

Status: Active » Fixed

Glad it all worked out!

mile23’s picture

Title: Non-use of hook_info in node_example » Better docs of 'base'=>'node_content' in node_example
Assigned: Unassigned » mile23
Category: support » task
Status: Fixed » Postponed

Here it is, clear as mud: http://drupal.org/node/224333#node_type_base Note that this is for hook_node_info() which is is apparently completely vestigial at this point. I thought I made a patch that documents some of this, but I can't find it. I'll wait until someone has rolled a few more commits and patch it.

Glad it worked for you, Cliff. :-)

cliffp’s picture

And it is also found as a comment in this article, in the API documentation.

http://api.drupal.org/api/drupal/modules--node--node.module/function/nod...

Of course, Murphy only let me find that after the problem had been solved for me by Mile23!

tr’s picture

Version: » 7.x-1.x-dev
Status: Postponed » Active

Reopening and setting version.

Anonymous’s picture

Assigned: mile23 » linclark

I'm doing a screencast that demos how to work in the issue queue, so I'm going to assign this to myself to use as an example. Mile23, feel free to take over again after tomorrow.

Anonymous’s picture

Status: Active » Closed (cannot reproduce)

I don't think that this hook is used in the node_example module anymore. I'm going to close this.

mile23’s picture

I should never have assigned it to myself. :-)

I was waiting for the big doxygen patch to happen.