Context: In my Drupal 7 project, I have a module with several submodules. Because the module's root directory got crowded, I moved the submodule files to their own directories within the root.
My module's structure is like this:
mymodule
├── mymodule.info
├── mymodule.module
├── mymodule1
│ ├── mymodule1.block.inc
│ ├── mymodule1.form.inc
│ ├── mymodule1.info
│ ├── mymodule1.module
│ ├── mymodule1.page.inc
│ └── pages
│ └── foo.tpl.php
└── mymodule2
├── classes
│ └── foo
│ └── Bar.php
├── mymodule2.form.inc
├── mymodule2.info
├── mymodule2.install
├── mymodule2.module
├── mymodule2.page.inc
└── pages
├── foo.tpl.php
└── bar.tpl.php
Before "the big move", files that are now in the subdirectories mymodule1
and mymodule2
, were located in their parent directory (the module's root directory).
The problem:
Ever since moving the files, my custom forms are not loading anymore. I have a form in mymodule1.form.inc
, which used to load and render perfectly before. Now, when I use drupal_get_form()
to load the form, I only get an empty form with a hidden build ID input.
Keep in the mind that the only thing that has changed here, is that the .inc files have been moved to the subdirectory, along with the module file. Also, drupal_get_path('module', 'mymodule1')
returns the correct path to the module in the subdirectory.
Strangely, there are also block hooks, located in mymodule1.block.inc
, which work perfectly fine, even after clearing all caches.
This is the first time I'm working with separate directories per submodule within a module. I got the inspiration from the module i18n
, which uses the same construction. I searched in the Drupal documentation and the code of i18n
, but could not find where I'm going wrong.
Does anyone know where I could possibly have gone wrong, or if I need to add data to mymodule1.module
or mymodule1.info
to make this work? Thank you.
Some details:
Caches were cleared through <path to project>/admin_menu/flush-cache
multiple times.
I use module1_hook_info()
to direct the hooks for blocks and forms to separate files. This is the return value:
array (size=9)
'block_info' =>
array (size=1)
'group' => string 'block' (length=5)
'block_configure' =>
array (size=1)
'group' => string 'block' (length=5)
'block_save' =>
array (size=1)
'group' => string 'block' (length=5)
'block_view' =>
array (size=1)
'group' => string 'block' (length=5)
'forms' =>
array (size=1)
'group' => string 'form' (length=4)
'form' =>
array (size=1)
'group' => string 'form' (length=4)
'form_validate' =>
array (size=1)
'group' => string 'form' (length=4)
'form_submit' =>
array (size=1)
'group' => string 'form' (length=4)
'form_alter' =>
array (size=1)
'group' => string 'form' (length=4)
My form functions are called:
mymodule1_foobar_form
mymodule1_foobar_form_validate
mymodule1_foobar_form_submit
mymodule1.form.inc
to include the new path?require_once
,module_load_include()
? I got the impression thatrequire_once
is bad practice.module_load_include()
- I reckon your original code worked because of an unintended side effect, more details in the answer