What is the purpose of files[] in .info?
I've just started learning discovering the changes to Drupal 7, and I just found the files[]
array now required in the mymodule.info
. From what I've found, it is required to add the mymodule.module
file to the list, but what other uses does it have?
From what I've read I figured I should be able to sepa开发者_高级运维rate my code into several files, for example I wanted to make a mymodule.blocks.inc
to contain all the code for my blocks, but it seems like the mymodule_block_info()
function never runs.
Am I doing something wrong, or is this not how it is supposed to be used?
As the documentation says:
files (Optional) Drupal now supports a dynamic-loading code registry. To support it, all modules must now declare any code files containing class or interface declarations in the .info file.
This is only used if the file you specify in files[]
contains a class or an interface. If so, the file will be auto-loaded only when needed.
No other files should be declared using files[]
.
At the beginning it was to make a files registry for each module, but it's not longer used as Drupal do it by himself.
If you want separate your module in multiple files, you should include them in the top of your .module file.
The way I see it, files specified as files[]
are meant to be supporting files and called upon when needed. Implemented default Drupal hooks should be specified in the .module
file or in the $module.$group.inc
file in order for Drupal to recognize them. See hook_hook_info().
Also, see the note in the documentation under files at http://drupal.org/node/542202.
精彩评论