I'm developing one custom module and I want to increase my module weight when the module is installed.
How can I achieve this? Otherwise, does anyone know in which table the module's weight is stored?
Use hook_module_implements_alter()
rather than changing the module weight.
Sample implementation from content_translation.module:
function content_translation_module_implements_alter(&$implementations, $hook) {
switch ($hook) {
// Move our hook_entity_type_alter() implementation to the end of the list.
case 'entity_type_alter':
$group = $implementations['content_translation'];
unset($implementations['content_translation']);
$implementations['content_translation'] = $group;
break;
// Move our hook_entity_bundle_info_alter() implementation to the top of the
// list, so that any other hook implementation can rely on bundles being
// correctly marked as translatable.
case 'entity_bundle_info_alter':
$group = $implementations['content_translation'];
$implementations = [
'content_translation' => $group,
] + $implementations;
break;
}
}
hook_module_implements_alter()
(actually happened to me, I think with one of the i18n modules).
Commented
Jan 12, 2016 at 10:45
There's an API for this now:
module_set_weight('your_module_name', 10);
You can also implement the hook as Ivan Jaros said, which allows for more fine-grained control (e.g. first for one hook, last for another, after a specific module for the third). But the module weight should work too.
If you use import/export configs, you can change module's weight in core.extension.yml
file, number after module's name is weight.
You can use the Modules weight module:
Sometimes we need to modify modules execution order, and some people could write a code that execute the query to modify the weight of a module in the system table, some one might go straight to his favorite SQL client and modify the record directly. This module provides an interface to reorder the modules weight.
Disclosure: I'm the maintainer of the module Modules Weight.