hook_features_enable_feature won't run for feature's dependency modules if they were disabled before. Here's the detailed scenario:

You have a feature A, which have a dependency for module B. Module B implementes hook_features_enable_feature() to initialize some of the feature A functionality. Both are disabled.

You go to the features list, select feature A and submit the form. Here's what goes on under the hood:
1. feature_admin_form() is run to rebuild the form.
2. It runs features_rebuild() which loads all features implementations in features_include() and static caches it. Note that at this point module B is not yet enabled, so it's implementation doesn't get to the cache.
3. after feature_admin_form() is rebuilt, the actual form submit function is executed.
4. It enables module B and feature A and runs hook_features_enable_feature() implementations. But since implementations are cached, module B is skipped.

The solution would be to reset static cache on step 4.

Patch attached.

Comments

neochief’s picture

hefox’s picture

Status: Needs review » Needs work

This seems like the incorrect place to reset the cache; ie if you were calling _features_restore (called from features_rebuild and features_revert?) several times in a page load, bam it's resetting it each time making it a rather useless static cache. This likely should be a one off event, like... hook_modules_enable?

neochief’s picture

Status: Needs work » Needs review

Thanks for your feedback, I've prepared a much better patch. It also fixes discovered bug with resetting features_include_defaults() (array_keys needed), apparently nowhere from code it was reset yet, so the bug wasn't discovered till now.

Please, review new version.

neochief’s picture

vladsavitsky’s picture

+1 . I would be glad to have this in features module.

neochief’s picture

Previous patch had flaw when you enable eatures through modules interface or drush. Here's updated one.

neochief’s picture

Fresh version of the patch.

neochief’s picture

Status: Needs review » Closed (won't fix)

I managed to create a work-around in install profile, which solved the problem for me. So, closing the issue.

neochief’s picture

I've found couple more issues about the same problem and moved all of my outcomes and updated patch there #1265168: Rebuild the file list properly when a feature is enabled or disabled.

Other minot issue solved by latest patch is here: #1510710: Incorrect key in features_include_defaults() with reset parameters