function hosting_features_form_submit in Hosting 6.2
Same name and namespace in other branches
- 5 hosting.features.inc \hosting_features_form_submit()
- 7.4 hosting.features.inc \hosting_features_form_submit()
- 7.3 hosting.features.inc \hosting_features_form_submit()
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 ./
hosting.features.inc - The Hosting features form.
File
- ./
hosting.features.inc, line 185 - Include for functionality related to Hosting module features.
Code
function hosting_features_form_submit($form, &$form_state) {
// Get form values, filtering out irrelevant entries.
$values = array_filter($form_state['values'], 'is_int');
$features = hosting_get_features();
// List of features currently enabled.
$enabled = array();
// List of features to enable.
$enable = array();
// List of features to disable.
$disable = array();
foreach ($features as $feature => $info) {
$value = $values['hosting_feature_' . $feature];
$current = $info['enabled'];
if ($current) {
$enabled[$features[$feature]['module']] = $features[$feature]['title'];
if (!$value) {
$disable[$features[$feature]['module']] = $features[$feature]['title'];
}
}
elseif ($value) {
$enable[$features[$feature]['module']] = $features[$feature]['title'];
// Add dependencies to enable
if (count($info['dependencies']['features'])) {
foreach ($info['dependencies']['features'] as $module_dep => $feature_dep) {
$enable[$module_dep] = $features[$feature_dep]['title'];
}
}
}
}
// Remove any features we're about to enable from those to disable.
$disable = array_diff_assoc($disable, $enable);
// Remove any features already enabled from those to enable.
$enable = array_diff_assoc($enable, $enabled);
include_once 'includes/install.inc';
// Enable the feature(s).
if (count($enable)) {
drupal_set_message(t("Enabling %feature feature!plural.", array(
'%feature' => implode(", ", $enable),
'!plural' => count($enable) > 1 ? 's' : '',
)));
drupal_install_modules(array_keys($enable));
foreach ($enable as $module => $feature) {
if (function_exists($callback = $features[$feature]['enable'])) {
$callback();
}
variable_set('hosting_feature_' . $feature, HOSTING_FEATURE_ENABLED);
}
}
// Disable the feature(s).
if (count($disable)) {
drupal_set_message(t("Disabling %feature feature!plural.", array(
'%feature' => implode(", ", $disable),
'!plural' => count($disable) > 1 ? 's' : '',
)));
module_disable(array_keys($disable));
foreach ($disable as $module => $feature) {
if (function_exists($callback = $features[$feature]['disable'])) {
$callback();
}
variable_set('hosting_feature_' . $feature, HOSTING_FEATURE_DISABLED);
}
}
// Rebuild schema.
drupal_get_schema(NULL, TRUE);
// Rebuild menu.
menu_rebuild();
// Record the enabled features in /var/aegir/.drush/drushrc.php
hosting_add_task(hosting_get_hostmaster_nid(), 'verify');
}