function _ctools_drush_selection_screen in Chaos Tool Suite (ctools) 7
Helper function to select the exportables. By default, all exportables will be selected, so it will be easier to deselect them.
Parameters
$tables:
1 call to _ctools_drush_selection_screen()
- ctools_drush_export in drush/
ctools.drush.inc - Drush callback: export.
File
- drush/
ctools.drush.inc, line 277 - CTools Drush commands.
Code
function _ctools_drush_selection_screen(array $tables = array()) {
$selections = $build = array();
$files = system_rebuild_module_data();
$selection_number = 0;
$info = _ctools_drush_export_info($tables, TRUE);
$exportables = $info['exportables'];
$schemas = $info['schemas'];
$export_tables = array();
foreach (array_keys($exportables) as $table) {
natcasesort($exportables[$table]);
$export_tables[$table] = $files[$schemas[$table]['module']]->info['name'] . ' (' . $table . ')';
}
foreach ($export_tables as $table => $table_title) {
if (!empty($exportables[$table])) {
$table_count = count($exportables[$table]);
$selection_number += $table_count;
foreach ($exportables[$table] as $key => $title) {
$build[$table]['title'] = $table_title;
$build[$table]['items'][$key] = $title;
$build[$table]['count'] = $table_count;
$selections[$table][$key] = $key;
}
}
}
drush_print(dt('Number of exportables selected: !number', array(
'!number' => $selection_number,
)));
drush_print(dt('By default all exportables are selected. Select a table to deselect exportables. Select "cancel" to start writing the files.'));
// Let's go into a loop.
$return = FALSE;
while (!$return) {
// Present the tables choice.
$table_rows = array();
foreach ($build as $table => $info) {
$table_rows[$table] = $info['title'] . ' (' . $info['count'] . ')';
}
$table_choice = drush_choice($table_rows, dt('Select a table. Select cancel to start writing files.'));
// Bail out.
if (!$table_choice) {
drush_log(dt('Selection mode done, starting to write the files.'), 'notice');
$return = TRUE;
return $selections;
}
// Present the exportables choice, using the drush_choice_multiple.
$max = count($build[$table_choice]['items']);
$exportable_rows = array();
foreach ($build[$table_choice]['items'] as $key => $title) {
$exportable_rows[$key] = $title;
}
drush_print(dt('Exportables from !table', array(
'!table' => $build[$table_choice]['title'],
)));
$multi_select = drush_choice_multiple($exportable_rows, $selections[$table_choice], dt('Select exportables.'), '!value', '!value (selected)', 0, $max);
// Update selections.
if (is_array($multi_select)) {
$build[$table_choice]['count'] = count($multi_select);
$selections[$table_choice] = array();
foreach ($multi_select as $key) {
$selections[$table_choice][$key] = $key;
}
}
}
}