You are here

function spaces_form_presets in Spaces 6

Same name and namespace in other branches
  1. 5.2 spaces.module \spaces_form_presets()
  2. 6.2 spaces.module \spaces_form_presets()

Preset options form that can be reused by implementing modules.

Parameters

$space: A space object.

Return value

A FormAPI array structure.

4 calls to spaces_form_presets()
spaces_basic_form in ./spaces_admin.inc
spaces_taxonomy_form_alter in spaces_taxonomy/spaces_taxonomy.module
spaces_user_user in spaces_user/spaces_user.module
Implementation of hook_user().
_spaces_og_form_alter_group in spaces_og/spaces_og.module
Group node form_alter(). @TODO: repair default values on node previews.

File

./spaces.module, line 1540

Code

function spaces_form_presets($space) {
  $presets = spaces_presets($space->type);
  if ($presets) {
    $default_presets = variable_get('spaces_default_presets', array());
    if (isset($space->preset) && !empty($presets[$space->preset])) {
      $default_preset = $space->preset;
    }
    else {
      if (isset($default_presets[$space->type])) {
        $default_preset = $default_presets[$space->type];
      }
      else {
        $default_preset = NULL;
      }
    }

    // Radios for presets
    $form = array(
      '#tree' => false,
      '#theme' => 'spaces_form_presets',
    );
    $form['preset'] = array(
      '#title' => t('Preset'),
      '#type' => 'radios',
      '#required' => true,
      '#options' => array(),
      '#default_value' => $default_preset,
    );
    $form['info'] = array();
    foreach ($presets as $id => $preset) {
      $form['preset']['#options'][$id] = $preset['name'];
      $form['info'][$id] = array(
        '#type' => 'item',
        '#title' => $preset['name'],
        '#description' => $preset['description'],
      );
    }
    return $form;
  }
  return array();
}