'admin/build/context/feature', 'title' => t('Add Spaces Feature'), 'description' => t('Add a new feature.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('context_ui_form', 'add'), 'access' => user_access('administer group features'), 'type' => MENU_LOCAL_TASK, 'weight' => 5, ); } return $items; } /** * Implementation of hook_context_define(). */ function spaces_ui_context_define() { $items = array(); $result = db_query('SELECT feature, label, description FROM {spaces_features_ui}'); while ($row = db_fetch_array($result)) { $c = new StdClass(); $c->namespace = 'spaces'; $c->attribute = 'feature'; $c->value = $row['feature']; if ($c = context_ui_context('load', $c)) { $c->spaces = $row; // A small change in context_ui now allows modules to // set system/status explicitly -- not recommended except for // cases like this. $c->system = 0; $c->status = 1; if (count($c->node)) { $c->spaces['options'] =_spaces_group_options(); } else { // For now we will use enabled/disabled options $c->spaces['options'] = array( 0 => t('Disabled'), 1 => t('Enabled'), ); } $items[] = (array) $c; } } return $items; } /** * Implementation of hook_form_alter() */ function spaces_ui_form_alter($form_id, &$form) { switch ($form_id) { case 'context_ui_form': if ($form['value']['#default_value']) { $feature = db_fetch_object(db_query('SELECT * FROM {spaces_features_ui} WHERE feature = "%s"', $form['value']['#default_value'])); } if (arg(3) == 'feature' || is_object($feature)) { // Add Feature information to context form $form['feature'] = array( '#type' => 'fieldset', '#title' => 'Feature Settings', '#weight' => -5, '#tree' => true, ); $form['feature']['label'] = array( '#type' => 'textfield', '#title' => t('Label'), '#description' => t('Name of the feature.'), '#required' => true, '#default_value' => $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' => $feature->description ? $feature->description : '', ); // 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_context_form_feature_submit'] = array(); } break; } } /** * Submit handler for spaces context_ui form alterations. */ function spaces_context_form_feature_submit($form_id, $form_values) { db_query('DELETE FROM {spaces_features_ui} WHERE feature = "%s"', $form_values['value']); db_query('INSERT INTO {spaces_features_ui} (feature, label, description) VALUES ("%s", "%s", "%s")', $form_values['value'], $form_values['feature']['label'], $form_values['feature']['description']); } ?>