.module files are not currently included during a modules installation. Although this is manageable for individual modules, it becomes a larger issue when you are try to create a complex installation file.
Attached is a simple patch to include a modules .module file before hook_install is called.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | include.module.patch | 625 bytes | mikejoconnor |
| include.module.patch | 633 bytes | mikejoconnor |
Comments
Comment #1
mikejoconnor commentedComment #3
mikejoconnor commentedRecreated the patch
Comment #4
damien tournoud commentedComment #5
moshe weitzman commentedFYI, I think we have the same issue for update functions. This looks like a good patch to me. Lets get more feedback.
Comment #6
damien tournoud commentedI got bitten by this one too. Let's get this in.
Comment #7
webchickI'm not sure about this change.
We use hook_requirements() to verify that pre-requisites exist prior to enabling a module and loading all of its code. For example, if I'm building ExternalLibrary module which requires ExternalLibrary.php to be in the includes directory, in hook_requirements() I can check to make sure that this is there *before* Drupal will load the .module code. Otherwise, I have to wrap all of my function calls to ExternalLibrary.php in my .module file within ugly function_exists() calls. Puke.
Can someone verify that this continues to work (denying the enabling of a module during hook_requirements() op install even when the .module contains functions that are not defined) even with this patch?
Comment #8
sunI quickly discussed with Damien in IRC, and the point is: the .module file has always been special... it makes sense to keep it this way.
If your module unconditionally tries to load additional files that do not ship with the module itself, that code should either run not in the global scope, or simply check for its existence.
Additionally, _drupal_install_module() is altered here, which only runs after any requirements have been met.
Comment #9
dries commentedI'm delegating this patch to webchick because of comment #7. Her call.
Comment #10
dww@webchick: Your module only has to conditionally check for the external file(s) in functions that you plan to invoke (directly or indirectly) inside hook_install() and hook_enable(). Simply including foo.module doesn't mean every code path in there is going to be evaluated. This should go in.
Comment #11
webchickOk, this was all I was asking for in #7, which looks like it wasn't clear:
example.info:
example.install:
example.module:
And making sure that fatal errors didn't spew everywhere when it was enabled.
But in the process of writing that, I just went ahead and did it, and confirmed that the error is caught before it includes the .module file. Committed to HEAD.
Please document in the 6.x => 7.x upgrade docs that people no longer need to do include this manually.
Comment #12
rfayComment #13
rfaySorry, @webchick, I'm ready to document but can't quite follow what you said. You say in #11 "Please document in the 6.x => 7.x upgrade docs that people no longer need to do include this manually".
What is it that people no longer need to do manually? Thanks.
Comment #14
webchickrfay, what I meant was an entry entitled like ".module file available during install" "In the past, in order to call a module's functions during any hooks within its .install file, you would have to have code like "include drupal_get('module', 'foo') .'/foo.module'; As of Drupal 7, the .module file and its functions are available in .install, once the hook_requirements() checks are satisfied."
Comment #15
rfayAdded this in http://drupal.org/update/modules/6/7#module_file_during_install