function hosting_features_form_submit in Hostmaster (Aegir) 6
Submit callback for the Hosting features form.
We process the submitted values and enable any features that the user has requested. This may involve enabling a module and their dependencies and/or calling a specified callback function.
Parameters
$form: The built form.
$form_state: The current form state.
See also
1 string reference to 'hosting_features_form_submit'
- hosting_features_form in modules/
hosting/ hosting.features.inc - The Hosting features form.
File
- modules/
hosting/ hosting.features.inc, line 112 - Include for functionality related to Hosting module features.
Code
function hosting_features_form_submit($form, &$form_state) {
$values = $form_state['values'];
$features = hosting_get_features(TRUE);
$module_cache = module_rebuild_cache();
foreach ($features as $feature => $info) {
$value = $values[$feature];
$current = hosting_feature($feature);
variable_set('hosting_feature_' . $feature, $value);
if (!$current && $value) {
if ($module = $features[$feature]['module']) {
include_once 'includes/install.inc';
$modules = array(
$module,
);
// Gather any dependencies to enable
foreach ($module_cache[$module]->info['dependencies'] as $dependency) {
if (!module_exists($dependency)) {
$modules[] = $dependency;
}
}
// Enable the module(s).
drupal_set_message(t("Enabling %module module!plural", array(
'%module' => implode(", ", $modules),
'!plural' => count($modules) > 1 ? 's' : '',
)));
drupal_install_modules($modules);
}
if (function_exists($callback = $features[$feature]['enable'])) {
$callback();
}
}
if ($current && !$value) {
$dependencies = array();
if ($module = $features[$feature]['module']) {
$modules = array(
$module,
);
$files = module_rebuild_cache();
foreach ($files as $dependency => $file) {
if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) {
if (in_array($module, $file->info['dependencies']) && $file->status) {
$dependencies[] = $dependency;
}
}
}
if ($dependencies) {
form_set_error('', t("You cannot disable %module because %dep depends on it", array(
'%module' => $module,
'%dep' => implode(', ', $dependencies),
)));
}
else {
drupal_set_message(t("Disabling %module module", array(
'%module' => implode(",", $modules),
)));
// turn off module
module_disable($modules);
if (function_exists($callback = $features[$feature]['disable'])) {
$callback();
}
}
}
}
#print("$feature $current $value $module <br />");
}
// Rebuild schema.
drupal_get_schema(NULL, TRUE);
// Rebuild menu.
menu_rebuild();
}