function spaces_preset_list in Spaces 7.3
Same name and namespace in other branches
- 6.3 spaces_ui/export_ui/spaces_presets_export_ui.class.php \spaces_preset_list()
- 7 spaces_ui/export_ui/spaces_presets_export_ui.class.php \spaces_preset_list()
Presets form.
1 string reference to 'spaces_preset_list'
- spaces_presets_export_ui::list_page in spaces_ui/
export_ui/ spaces_presets_export_ui.class.php - Master entry point for handling a list.
File
- spaces_ui/
export_ui/ spaces_presets_export_ui.class.php, line 25
Code
function spaces_preset_list($form, &$form_state, $export_ui) {
// Some setup for the spaces_preset_name_validation
$form_state['plugin'] = $export_ui->plugin;
$form_state['object'] =& $export_ui;
$types = array();
foreach (spaces_types(TRUE) as $type => $info) {
$types[$type] = $info['title'];
}
$form['new'] = array(
'#tree' => FALSE,
'#theme' => 'spaces_preset_list_new',
'space_type' => array(
'#title' => t('Type'),
'#type' => 'select',
'#options' => $types,
),
'name' => array(
'#type' => 'textfield',
'#maxlength' => 64,
'#size' => 32,
'#title' => t('Machine ID'),
'#element_validate' => array(
'spaces_preset_name_validate',
),
),
'title' => array(
'#type' => 'textfield',
'#maxlength' => 64,
'#size' => 32,
'#title' => t('Name'),
),
'submit' => array(
'#type' => 'submit',
'#value' => t('Create new preset'),
'#submit' => array(
'spaces_preset_list_new',
),
),
);
// Generate preset options.
foreach ($types as $type => $title) {
module_load_include('inc', 'spaces', 'spaces.admin');
$presets = spaces_preset_load(NULL, $type, TRUE);
ksort($presets);
$form[$type] = spaces_preset_form($presets, $type, TRUE);
$form[$type]['#title'] = t('@spacetype presets', array(
'@spacetype' => $title,
));
$form[$type]['#description'] = t('Select a default preset for each new @spacetype.', array(
'@spacetype' => $title,
));
$plugin = $export_ui->plugin;
foreach ($presets as $name => $item) {
// Note: Creating this list seems a little clumsy, but can't think of
// better ways to do this.
$allowed_operations = drupal_map_assoc(array_keys($plugin['allowed operations']));
$not_allowed_operations = array(
'import',
);
if ($item->type == t('Normal')) {
$not_allowed_operations[] = 'revert';
}
elseif ($item->type == t('Overridden')) {
$not_allowed_operations[] = 'delete';
}
else {
$not_allowed_operations[] = 'revert';
$not_allowed_operations[] = 'delete';
}
$not_allowed_operations[] = empty($item->disabled) ? 'enable' : 'disable';
foreach ($not_allowed_operations as $op) {
// Remove the operations that are not allowed for the specific exportable.
unset($allowed_operations[$op]);
}
$operations = array();
foreach ($allowed_operations as $op) {
$operations[$op] = array(
'title' => $plugin['allowed operations'][$op]['title'],
'href' => ctools_export_ui_plugin_menu_path($plugin, $op, $name),
);
if (!empty($plugin['allowed operations'][$op]['token'])) {
$operations[$op]['query'] = array(
'token' => drupal_get_token($op),
);
}
}
$form[$type]['storage'][$item->name] = array(
'#type' => 'markup',
'#markup' => check_plain($item->type),
);
$form[$type]['actions'][$item->name] = array(
'#type' => 'markup',
'#markup' => theme('links', array(
'links' => $operations,
)),
);
}
}
$form = system_settings_form($form);
return $form;
}