just looking for some quick clarification on a "hooks" rule
work77 - November 6, 2009 - 23:44
Is it absolutely required for your hook names to match the module name or do they just have to have a unique name. Using the module name just ensures there won't be naming conflicts?

It is absolutely required for hooks
For other functions (not hooks) it just ensures there won't be naming conflicts. But hooks must begin with the module name, otherwise the hook system won't find them - as it looks through the list of enabled modules when searching for hooks to invoke.
-
So, what is hook_form do then ( http://api.drupal.org/api/function/hook_form )? Doesn't the $form array HAVE to be defined in there? Or can it be any name which would explain why the below is correct from ( http://drupal.org/node/206761 )?
When I see my_module_form() is that use of a hook or just a suggestion for a function name to prevent conflict? I'm pretty confused.
<?php
function onthisdate_admin() {
$form = array();
$form['onthisdate_maxdisp'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of links'),
'#default_value' => variable_get('onthisdate_maxdisp', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("The maximum number of links to display in the block."),
'#required' => TRUE,
);
return system_settings_form($form);
}
?>
Ah. Well, hook_form is a bit
Ah. Well, hook_form is a bit different. It's for node modules, it allows you to define a form for the node type(s) your module defines. It's not used for any other forms.
It's a bit confusing because hook_form and the other node module "hooks" (hook_insert, hook_update, hook_delete etc) are not really hooks in the usual sense at all. They're more like callbacks. They don't necessarily begin with the module name, rather they begin with a prefix that you define in hook_node_info() - which may be the module name, or may be based on the module name, or may (but should not) be something else entirely. It's the value of the "module" key in the array returned from hook_node_info.
However, my_module_form() by itself, as a name, doesn't mean anything in particular. If you define a form for something other than a node, you can call the form builder function any name you want. It's not a hook.
Are you sure about hook_form
Are you sure about hook_form taking the node type name as the hook name, and not the module? I haven't tested this, but I have used content type names different from the module name, and still been able to use hook_form with the module name - I've never used the name defined in hook_node_info(). I'm not saying you are wrong, I just want to clarify that its correct, since it's new info to me.
I'm sure that it uses the
I'm sure that it uses the "module" key from hook_node_info, as I said. Note that this is not necessarily the same as the actual node type name, and indeed it is usually the same as the module name - but need not be. For example you can have two different node types with the same "module" key defined, and they will use the same hook_form (and hook_insert etc.) callbacks. Or you can have two different node types defined by the same module, but with different "module" keys, and they will use different callbacks.
Example:
<?phpfunction my_module_node_info() {
return array(
'my_node_type' => array( // <-- this is the node type name, which is not used
'name' => t('my node type'),
'module' => 'my_hooks_start_with_this', // <-- this is the "module" key, which is used
'description' => t("This is just an example."),
)
);
}
?>
In this case, your hook_form would be named my_hooks_start_with_this_form().
my_module_form() or my_node_type_form() would not work.
Thanks for the clarification.
Thanks for the clarification. I guess I've always named my content types the same as my node types, because I never noticed that behavior before. You probably just saved me some frustrating debugging sometime in the future!