The .module file extension has been deprecated. Support for autoloading the .module files will be removed in Drupal 13.
All functions in .module files should be converted to the appropriate object-oriented replacement.
See the rector script and change records below for assistance.
To simplify your conversion, set your module's minimum version requirement to Drupal 11.3.0. (If you still support earlier versions, the CR's give information about how to handle backwards compatibility.)
Hooks and hook helper functions
All hook implementations should be moved to object-oriented classes with the appropriate attributes.
Most hooks can just use the #[Hook] attribute.
The following hooks require special treatment:
- hook_requirements(_alter)
- template_preprocess_HOOK
- hook_module_implements_alter
- hook_hook_info (Removed in Drupal 12)
Most hook helper functions should move to a utility service or method on the hook class using it.
Other procedural functions
Other functions should be moved to services.
If your module has functions other projects rely on, add a deprecation warning for those functions and have them call the service replacing them.
Some functions are generally safe to replace without BC.
- hook implementations
- hook helper functions
- form callbacks
- batch callbacks
Converting your module's code with rector
A rector rule with a helpful DDEV script exists to assist with converting hooks. It will convert all hooks with the correct Implements hook_foo() documentation.
You can use https://search.tresbien.tech/ to gauge your module's function's usage across Drupal contrib.
There is an attribute #[ExtensionFileIsConverted] that can be used to silence any deprecations once the .module file is fully converted. This attribute is only needed if you must maintain the .module file for backwards compatibility purposes.
Note: The attribute only disables the upcoming deprecation message, the files will all no longer be auto-loaded in Drupal 13.