We have a series of feature modules that are used on different sites, but not every site has every feature enabled.
Surprisingly for me, on every site all exported menu links got imported, regardless whether the feature module was enabled or not.

For building the menu links, features_get_default('menu_links') is called, which loads all feature modules and calls the default hooks. And before a default hook function is invoked, module_hook() is used for checking the existence of the function. According to the documentation (http://api.drupal.org/api/drupal/includes!module.inc/function/module_hook/7) this function only returns TRUE "if the module is both installed and enabled, and the hook is implemented in that module", but if you look into module_hook() you'll see that only function_exists() is called, which ignores the module status.

As either the documentation or the implementation is wrong (IMO the implementation), it is actually a core bug and there are already two issues, at least for D8: #1850988: Should module_hook() check module_exists()? and #1850992: Make module_hook() check for module_exists() first.

I'm not sure if this is every going to be fixed in D7, so at least I'll post a simple patch for the features module afterwards. Not sure if this has some side-effects and if other components than menu links are affected.

CommentFileSizeAuthor
#1 1909522-features_module_enabled_check-1.patch881 bytesmh86

Comments

mh86’s picture

Status: Active » Needs review
StatusFileSize
new881 bytes

And here a simple workaround for features

mh86’s picture

Status: Needs review » Closed (duplicate)