Skip to content

Instantly share code, notes, and snippets.

@mootari
Last active August 29, 2015 14:20
Show Gist options
  • Save mootari/5f3eb14d54d4268833b2 to your computer and use it in GitHub Desktop.
Save mootari/5f3eb14d54d4268833b2 to your computer and use it in GitHub Desktop.
To be called from hook_install()
/**
* Fixes an issue with node type permissions in features.
*
* Temporarily implements hook_module_implements_alter().
* Temporarily implements hook_modules_enabled().
*
* When a node type feature gets enabled, the node type
* cache does not get regenerated immediately.
* This causes node type specific permissions to be missing
* when subsequent features are enabled that set
* those permissions.
*
* This function implements two hooks for the current
* request to override Features' own implementation of
* hook_modules_enabled.
*/
function MODULE_features_fix_node_type_cache() {
static $enabled = false;
if(!$enabled) {
/**
* Implements hook_module_implements_alter().
*
* Disables hook_modules_enabled() for Features in order to
* reimplement it.
*/
function MODULE_module_implements_alter(&$modules, $hook) {
if($hook === 'modules_enabled' && isset($modules['features'])) {
unset($modules['features']);
}
}
/**
* Implements hook_modules_enabled().
*
* Implements the hook on behalf of Features. Includes
* node features to ensure that custom content type
* permissions are known to follow-up features.
*/
function MODULE_modules_enabled($modules) {
if(!module_exists('features')) {
return;
}
foreach($modules as $module) {
// Call the features hook implementation
features_modules_enabled(array($module));
$info = system_get_info('module', $module);
// Check for node components
if(!empty($info['features']['node'])) {
// Make sure the hook_node_info() implementation
// has been declared
module_load_include('module', $module);
// Purge the node type cache
node_type_cache_reset();
}
}
}
}
$enabled = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment