1 installer.pages.inc | installer_browser_installation_enable_form($form, &$form_state, $projects) |
Form builder for the select versions form.
Parameters
$projects: An array of projects selected for install, keyed by project name.
File
- core/
modules/ installer/ installer.pages.inc, line 645 - Page callbacks used by the Installer browse pages.
Code
function installer_browser_installation_enable_form($form, &$form_state, $projects) {
$modules = system_rebuild_module_data();
// Go through each of the installed projects and add any contained submodules
// that are not hidden to the list of projects.
foreach ($projects as $project) {
if ($project['type'] == 'module' && isset($modules[$project['name']])) {
foreach ($modules as $module) {
// Ignore stand-alone and hidden modules.
if (!isset($module->info['project']) || !isset($modules[$project['name']]->info['project']) || !empty($module->info['hidden'])) {
continue;
}
// The "type" key is required. Skip over any (sub)module not specifying
// it in its .info file.
if (!isset($module->info['type'])) {
continue;
}
// Collect information about sub-modules.
if ($modules[$project['name']]->info['project'] == $module->info['project'] && $modules[$project['name']]->name != $module->name) {
$projects[$module->name] = array(
'type' => $module->info['type'],
'title' => $module->info['name'],
'name' => $module->name,
);
}
}
}
}
$options = array();
$missing = array();
foreach ($projects as $project) {
if ($project['type'] == 'module') {
$dependency_check = TRUE;
$dependencies = array();
if (isset($modules[$project['name']])) {
foreach ($modules[$project['name']]->requires as $dependency_name => $dependency_info) {
if (isset($modules[$dependency_name])) {
$dependency_version = $modules[$dependency_name]->info['version'];
if (backdrop_check_incompatibility($dependency_info, $dependency_version)) {
$dependency_check = FALSE;
$dependency_version_string = trim($dependency_info['original_version'], '()');
$dependencies[] = $dependency_name . ' (' . t('Requires version @version', array('@version' => $dependency_version_string)) . ')';
}
else {
$dependencies[] = $modules[$dependency_name]->info['name'] . ' (<span class="admin-enabled">' . t('installed') . '</span>)';
}
}
else {
$dependency_check = FALSE;
$dependencies[] = $dependency_name . ' (<span class="admin-missing">' . t('missing') . '</span>)';
}
}
// Build the list of options, but only include (sub)modules that are not
// hidden. This check also helps with the rare case where the main
// module within a project needs to be hidden, and submodules enabled
// instead. See https://github.com/backdrop/backdrop-issues/issues/5054.
if (empty($modules[$project['name']]->info['hidden'])) {
if ($dependency_check) {
$options[$project['name']] = array(
array('data' => $modules[$project['name']]->info['name']),
array('data' => $modules[$project['name']]->info['version']),
array('data' => implode(', ', $dependencies)),
);
}
else {
$missing[$project['name']] = array(
array('data' => $modules[$project['name']]->info['name']),
array('data' => $modules[$project['name']]->info['version']),
array('data' => implode(', ', $dependencies)),
);
}
}
}
else {
backdrop_set_message(t('There was an error getting information for @module',
array('@module' => $project['name'])), 'error');
}
}
}
$headers = array(
array('data' => t('Title')),
array('data' => t('Version'), 'class' => array('priority-medium')),
array('data' => t('Dependencies'), 'class' => array('priority-low')),
);
$all_options = array_merge($options, $missing);
ksort($all_options);
if (!empty($all_options)) {
$form['module_instructions'] = array(
'#type' => 'item',
'#markup' => t('You may enable modules using the form below or on the main !link page.', array('!link' => l(t('Modules'), 'admin/modules'))),
);
$form['modules'] = array(
'#type' => 'tableselect',
'#title' => t('Enable modules'),
'#description' => t('Select which modules you would like to enable.'),
'#header' => $headers,
'#options' => $all_options,
'#empty' => t('No new modules installed.'),
'#multiple' => TRUE,
'#js_select' => TRUE,
'#weight' => 1,
);
// Disable the checkboxes of any module that has unmet dependencies.
foreach ($all_options as $key => $value) {
if (in_array($key, array_keys($missing))) {
$form['modules'][$key]['#disabled'] = TRUE;
}
}
// Show the "Enable modules" button only if there are modules that can be
// enabled (at least one module without any missing dependencies).
if (!empty($options)) {
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#submit' => array('installer_browser_installation_enable_form_submit'),
'#value' => t('Enable modules'),
);
}
// If there is at least one module in the list (even one that cannot be
// enabled due to unmet dependencies), then show the "Finish without
// enabling" link.
if (!empty($all_options)) {
$form['actions']['cancel'] = array(
'#type' => 'link',
'#name' => 'cancel',
'#title' => t('Finish without enabling'),
'#href' => 'admin/installer/reset/module/all',
'#options' => array(),
);
}
// If there is at least one module with unmet dependencies, then show a
// warning to explain why these modules in the list have no checkboxes.
if (!empty($missing)) {
backdrop_set_message(t('Some modules are missing one or more dependencies and cannot be enabled. The checkboxes for these modules have been disabled.'), 'warning');
}
}
return $form;
}