The documentation for implementing hook_load(), hook_delete(), hook_prepare(), hook_insert(), hook_validate(), hook_update() and hook_view() is unclear at best, incorrect at worst.
These modules are not implemented using the module name as the base name, but the node type's "base" instead. The documentation does not suggest that and the documentation that does explain it (in hook_node_info()) could be improved.
This patch seeks to correct the errors and improve the documentaion, including three textual examples of how one can use hook_node_info() and node type "base" to implement these hooks effectively.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2309549-8.patch | 7.52 KB | er.pushpinderrana |
#8 | interdiff-2309549-6-8.txt | 657 bytes | er.pushpinderrana |
#6 | 2309549-5.patch | 7.47 KB | er.pushpinderrana |
Comments
Comment #1
Bevan CreditAttribution: Bevan commentedComment #2
jhodgdonWow, good catch! This issue report is accurate -- if you look at function node_invoke(), which actually does the invokes, it is doing what you say.
However, I think the patch itself needs some work:
a) Proofreading -- such as spelling and "it's" instead of "its".
b) There are extra spaces (do not leave two spaces between sentences, only one).
c) I think it is a bit confusing. It could be pretty simple. Just say essentially:
When you define a node type, you give it a "base". All of the node-type-specific hooks (list them), instead of being named mymodule_hookname(), as they would be for normal hooks in module mymodule, are named base_hookname() instead.
I don't think the documentation needs to be this verbose.
Comment #3
Bevan CreditAttribution: Bevan commentedThanks @jhodgdon! I tried really hard to make it as simple as possible, but I guess what I really needed was fresh eyes!
Also, I found that
@defgroup node_api_hooks Node API Hooks
attempts to cover this topic, but does so misleadingly too.I like your phrasing:
hook_node_info()
. I fixed that.node_api_hooks
group already lists all hooks, noting the node-type-specific ones.node_api_hooks
group.hook_form()
, which was missing it, even though it is node-type-specific. (See$function = node_type_get_base($node) . '_form'
innode_form()
).@node_api_hooks
inhook_node_info()
and all node-type-specific hooks.hook_form()
. Seenode_content_form()
: It is impossible to define a content type without implementing hook_form().Also; I am not sure how to set a new paragraph inside a list item? Or if that is even possible via doxygen, and how to test it. Do you know?
Comment #4
Bevan CreditAttribution: Bevan commentedComment #5
jhodgdonThis is great!
A few minor things to fix:
a) Lists in API documentation do not support paragraph breaks within a single list item. So you should just wrap the text together, in:
b) You cannot use @see inside of documentation paragraphs. @see goes at the end. Use @link to make links within text. So:
should become something like
And
needs a similar change.... but maybe on each hook we should say something like:
This is a node-type-specific hook, which is invoked only for the node type being affected. Also, instead of the function name prefix being the module name, it is the "base" of the node type. See @link node_api_hooks Node API hooks @endlink for more information.
It seems like it is pretty important here to know that the function name is not like other hooks?
Comment #6
er.pushpinderrana CreditAttribution: er.pushpinderrana commentedIncorporated above mentioned changes in this patch. Please review updated patch.
Comment #7
jhodgdonLooks great!
I did notice one thing I think we should fix, in hook_form():
We should not advise using hook_form_alter(). People would be better of using hook_form_BASE_FORM_ID() alter, since it is more specific. So we should say something like:
Use hook_form_BASE_FORM_ID_alter(), with base form ID 'node_form', to alter node forms for all node types.
The rest looks perfect, thanks!
Comment #8
er.pushpinderrana CreditAttribution: er.pushpinderrana commentedPlease review updated patch with #7 changes.
Comment #9
jhodgdonThanks for the quick update!
Comment #10
jhodgdonThanks again! Committed to 7.x.
Comment #12
Bevan CreditAttribution: Bevan commentedThanks @er.pushpinderrana!
Comment #14
jhodgdon