A contributed module that I am using [popup_forms] uses module_invoke_all to check whether any modules have defined a form for it to use.

I have defined the necessary function called mymodule_popup_forms_data() that provides the information that popup_forms needs.

If I locate that function within mymodule.module, all works well.

If, however, I move that function to a mymodule.inc file, then the module_invoke_all in popup_forms does not find my function.

This despite trying a very large number of variations of module_load_include, include_once etc. etc. etc. I think that there might be a hint to what is going on in a greg.harvey comment five years ago:

"Worth noting, if you want to include data (e.g. a views object) in an include file, you cannot use this function - because the data will only be available within the scope of module_load_include() function, not within your own function that invoked it."

Hence the question: Is it true that a function defined in a .inc file that is included via a module_load_include call will not be "in scope" for module_invoke_all?

Comments

wdseelig created an issue. See original summary.

cilefen’s picture

Title: Scope of functions for invocation by module_invoke_all » Scope of functions for invocation by module_invoke_all seems to not include .inc files
Component: menu system » base system
Assigned: wdseelig » Unassigned
Issue tags: -Scope, -functions

Have you tried the files[] key to specify the .inc file in your module info file?

cilefen’s picture

Or, require_once() the .inc file in your .module file? There is no way Drupal will know to load the functions some .inc file unless it is referenced somewhere.

Version: 7.15 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.