Skip to content

Instantly share code, notes, and snippets.

@derhasi
Last active August 29, 2015 14:05
Show Gist options
  • Save derhasi/e73496c035376d877feb to your computer and use it in GitHub Desktop.
Save derhasi/e73496c035376d877feb to your computer and use it in GitHub Desktop.
Snippet for making features components of disabled modules available again.
<?php
/**
* @file
* Make features components of disabled modules available again.
*/
/**
* Implements hook_system_info_alter().
*/
function mycustom_system_info_alter(&$info, $file, $type) {
static $files_status = array();
// We want to remove features info from disabled obsolete modules, so we get a
// clean component list with all available components.
// First check if there is any features info first and quit otherwise.
if (!isset($info['features'])) {
return;
}
// Get file status, so we can check if it is enabled currently.
if (empty($files_status)) {
$files_status = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => 'module'))
->fetchAllAssoc('filename');
}
// Quit if we have no file status yet.
if (!isset($files_status[$file->filename])) {
return;
}
// Also do nothin if the module is enabled.
elseif (!empty($files_status[$file->filename]->status)) {
return;
}
// Optionaly we could kick only modules with a given name or folder:
// We only want to "kick" obsolete modules, so ignore anyone else.
//if (strpos($file->filename, 'obsolete') === FALSE ) {
// return;
//}
// otherwise remove the features info.
unset($info['features']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment