function spaces_ui_form_alter in Spaces 5.2
Same name and namespace in other branches
- 5 spaces_ui.module \spaces_ui_form_alter()
Implementation of hook_form_alter()
File
- ./
spaces_ui.module, line 78
Code
function spaces_ui_form_alter($form_id, &$form) {
switch ($form_id) {
case 'context_ui_delete_confirm':
$cid = $form['cid']['#value'];
$context = context_ui_context('load', $cid);
if ($context->namespace == 'spaces' && $context->attribute == 'feature') {
$form['spaces_feature'] = array(
'#type' => 'value',
'#value' => $context->value,
);
$form['#submit']['spaces_ui_feature_delete'] = array();
$form['#submit'] = array_reverse($form['#submit']);
}
break;
case 'context_ui_form':
// Determine whether we should treat this context as a spaces feature
if ($form['namespace']['#default_value'] == 'spaces' && $form['attribute']['#default_value'] == 'feature') {
$is_feature = TRUE;
}
else {
$is_feature = FALSE;
}
// Load feature information: first attempt from DB, then fallback
// to code definition.
if (!empty($form['value']['#default_value'])) {
$id = $form['value']['#default_value'];
$row = db_fetch_object(db_query('SELECT * FROM {spaces_features_ui} WHERE feature = "%s"', $id));
if ($row) {
$feature = unserialize($row->value);
}
else {
$features = spaces_features();
if (isset($features[$id])) {
$feature = $features[$id]->spaces;
}
}
}
// Add Feature information to context form
$form['feature'] = array(
'#type' => 'fieldset',
'#title' => t('Spaces feature'),
'#weight' => -5,
'#tree' => true,
);
$form['feature']['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#description' => t('Name of the feature.'),
'#required' => true,
'#maxlength' => 30,
'#default_value' => isset($feature['label']) ? $feature['label'] : '',
);
$form['feature']['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('A brief description of the feature.'),
'#required' => true,
'#default_value' => isset($feature['description']) ? $feature['description'] : '',
);
// Space type compatibility
$options = array(
0 => t('All spaces'),
);
foreach (spaces_types() as $type => $info) {
$options[$type] = $info['title'];
}
$form['feature']['types'] = array(
'#type' => 'select',
'#title' => t('Compatibility'),
'#description' => t('Choose the space type compatible with this feature.'),
'#required' => true,
'#options' => $options,
'#default_value' => isset($feature['types']) ? $feature['types'] : 0,
);
// Spaces feature menu
$menu_items = isset($feature['menu']) ? array_values($feature['menu']) : array();
$menu_paths = isset($feature['menu']) ? array_keys($feature['menu']) : array();
$form['feature']['menu'] = array(
'#tree' => true,
'#theme' => 'spaces_ui_feature_form_menu',
);
$form['feature']['menu']['help'] = array(
'#title' => t('Feature menu'),
'#type' => 'item',
'#description' => t('Define a menu for this feature. Items will be arranged into a tree based on path. <strong>Example:</strong> "gallery/browse" will become a child item of "gallery".'),
);
for ($i = 0; $i < 10; $i++) {
$form['feature']['menu'][$i] = array(
'#tree' => true,
);
$form['feature']['menu'][$i]['path'] = $form['feature']['menu'][$i]['title'] = array(
'#type' => 'textfield',
'#size' => 30,
);
$form['feature']['menu'][$i]['path']['#default_value'] = isset($menu_paths[$i]) ? $menu_paths[$i] : '';
$form['feature']['menu'][$i]['title']['#default_value'] = isset($menu_items[$i]['title']) ? $menu_items[$i]['title'] : '';
}
// Force key and space to be 'feature', 'spaces' so that the spaces module knows what to do.
$form['attribute']['#disabled'] = true;
$form['attribute']['#default_value'] = 'feature';
$form['namespace']['#disabled'] = true;
$form['namespace']['#default_value'] = 'spaces';
$form['#submit']['spaces_ui_feature_form_submit'] = array();
$form['#submit'] = array_reverse($form['#submit']);
$form['#redirect'] = 'admin/build/spaces/features';
break;
}
}