View source
<?php
function spaces_ui_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => '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;
}
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;
$c->system = 0;
$c->status = 1;
if (count($c->node)) {
$c->spaces['options'] = _spaces_group_options();
}
else {
$c->spaces['options'] = array(
0 => t('Disabled'),
1 => t('Enabled'),
);
}
$items[] = (array) $c;
}
}
return $items;
}
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)) {
$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 : '',
);
$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;
}
}
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']);
}