You are here

spaces_ui.module in Spaces 5

Same filename and directory in other branches
  1. 5.2 spaces_ui.module

File

spaces_ui.module
View source
<?php

/**
 * Implementation of hook_menu().
 */
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;
}

/**
 * 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']);
}

Functions

Namesort descending Description
spaces_context_form_feature_submit Submit handler for spaces context_ui form alterations.
spaces_ui_context_define Implementation of hook_context_define().
spaces_ui_form_alter Implementation of hook_form_alter()
spaces_ui_menu Implementation of hook_menu().