So this is pretty experimental, but I was curious if I could manage the enabled/disabled state of modules via Features, rather than having to write a small update hook. Modules that are not necessarily dependencies of anything. Just more like "hey I want to turn on the Entity Cache module."

And it's kind of a nice way to capture in code the history of enabled or disabled modules.

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new3.43 KB
chx’s picture

I think system_features_export always returns an empty array.

dave reid’s picture

@chx: It's exported using the $data array. It doesn't need to pipe any additional information through. It's an odd return structure for that hook, but that's what it expects: http://drupalcontrib.org/api/drupal/contributions!features!features.api....

chx’s picture

OMG you mean the &$export array. I missed that. Oh well. Features :)

frankcarey’s picture

Nice :) I don't see any options for it though. Should this show up in the UI?

frankcarey’s picture

features.system.inc was placed in the root and not features/includes. This patch *should* fix that, but was hand-edited, so cross your fingers :)

Also, here is a snapshot of the new option in the UI for those looking for it. It's under "System", and it doesn't have a setting per module as I expected, but I can imagine that is so newly enabled modules can be identified automatically?

Screenshot of system export setting

Status: Needs review » Needs work

The last submitted patch, 6: features-export-enabled-modules-2341769-6.patch, failed testing.

dave reid’s picture

+++ b/features.module
diff --git a/includes/features.system.inc b/includes/features.system.inc
new file mode 100644
index 0000000..c534dcf
--- /dev/null
+++ b/includes/features.system.inc
@@ -0,0 +1,93 @@

The original patch definitely had the correct location for the include?

dave reid’s picture

It's definitely intended to not be per-module since it's an export of the 'currently enabled modules' state.

frankcarey’s picture

You are correct, not sure why my patch command didn't place it there, I should have checked the patch more closely. That said, this still wasn't working for me until I changed system_features_export() to just output 'modules' and not all of the actual modules. The code seemed to be exporting all of the modules in 2 places for some reason resulting in the if statement failing.

/**
 * Implements hook_features_export_render().
 */
function system_features_export_render($module, $data, $export = NULL) {
  $code = array();
  $code[] = '  $system = array();';
  $code[] = '';
  // NAME WAS AN ARRAY ..SOMETIMES :/
  foreach ($data as $name) {
    if ($name == 'modules') {
      $system_export = features_var_export(_system_features_get_modules(), '  ');
      $code[] = "  \$system['modules'] = {$system_export};";
    }
  }

I also removed system_features_rebuild() (and moved the code to system_features_revert()) since it meant that every cache clear and visits to the modules page or features pages caused the enabled modules to all be reverted. I could see that being useful in production, but it was a PITA in development when you have modules like devel enabled.

I'm still trying to think how this could work where the enabled modules were individual items... Maybe one "all" option as the first, followed by individual modules as well? Then you could do things like exclude dev modules... Just added this contrib module which allows you to "banish" features components from showing up anywhere. https://www.drupal.org/project/features_banish and it would be useful to "banish" dev and ui modules from being reverted while working locally.

frankcarey’s picture

Status: Needs work » Needs review
frankcarey’s picture

Looks like hook_features_system_defaults_alter(&components) can be used for what I'm looking to do (add or remove defaults based on environment, like with dev modules.

This code will disable the dev modules if they were exported for instance:

function my_module_features_system_defaults_alter(&$defaults) {
 $dev_modules = array(
    'bulk_export',
    'ds_ui',
    'devel',
    'field_ui',
    'update',
    'views_ui',
  );

  if (isset($defaults['modules'])) {
    foreach($dev_modules as $module) {
      unset($defaults['modules'][$module]);
    }
  }
} 
hefox’s picture

To quickly summerize, you want to have modules enabled, but not list them as dependencies to the feature?

So, if I recall correctly, what I did for that in d6 (private) install profile was have a recommends[] key that enable by default but not dependencies. I remember there was a contrib module or maybe a core issue queue along those lines, but don;t recall details.

frankcarey’s picture

FYI, I just turned this into it's own module. https://www.drupal.org/project/features_master

Feedback very welcome :)

digitgopher’s picture

Status: Needs review » Closed (fixed)

Assuming the spin off module takes care of this issue.