By I am learning on
I've written my first module with lots of help from this forum, thanks guys. I would love to know about .inc files, why should we use them? and off course how to? please provide a link where I can read about it.
Thanks
Comments
A module has to have at least
A module has to have at least a .info and .module file. When Drupal loads a page all .module files (of active modules) are loaded. So one use of .inc files is with hook_menu() which allows you to specify a path, callback function and optionally a file to load. This helps to reduce code loaded on each page since the .inc file is only loaded for the specific path.
In one of my modules
In one of my modules (uc_affiliate2), the admin pages get their own inc file, while the user pages get their own inc file. The .module handles the rest (generic functionality, often needed by both inc files).
That way you separate the code a bit, gaining readability and maintainability,
Thnaks, I got it. I've
Thnaks, I got it.
I've separated my hooks and other functions accordingly, changed in the hook_menu by specifying the my_module.inc file and they are working as earlier.
Now hook_form
function my_module_form()and a function to create another formfunction my_module_add() {both are doing the same job of creating a form using the Forms API and fires validate and submit. My confusion is when we can implement forms using the API in a normal function then why hook_form? I may sound stupid but I've just started with Drupal module development :-)Regards
hook_form() is only used when
hook_form() is only used when developing new content types, not for custom forms. hook_form() always needs to be in the .module file, as do all other hooks.
Contact me to contract me for D7 -> D10/11 migrations.
hmmm... okay, you mean for my
hmmm... okay, you mean for my custom table I don't need a hook_form at all?
Exactly. If you are not
Exactly. If you are not defining a new content type, you don't use it.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks
Thanks
.inc file are loaded only when they are requested..
The .inc files are created when you've complex module functionality and want to break down it into many other files. In such scenarios, in order to create and maintain functionality of complex module easily, these .inc files are created; other reasons are also present. These .inc files are included in .module file to implement the functionality. Moreover, thee .inc files are loaded only when they are requested, and .module files are loaded on every load page. .inc files can be included by mentioning the path in hook_menu(), or by making an explicit using module_load_include('inc', 'node', 'node.admin').
See ref: https://drupal.stackexchange.com/questions/54051/difference-between-inc-...