You are here

function spaces_customize_form in Spaces 6

Same name and namespace in other branches
  1. 5.2 spaces_admin.inc \spaces_customize_form()
  2. 6.2 spaces_admin.inc \spaces_customize_form()

Feature customization form.

1 string reference to 'spaces_customize_form'
spaces_features_page in ./spaces_admin.inc
FEATURE SETTINGS ===================================================

File

./spaces_admin.inc, line 808

Code

function spaces_customize_form(&$form_state, $space = NULL, $feature) {

  // Attempt to get current space if not provided
  $space = !isset($space) ? spaces_get_space() : $space;
  $form = array();
  $form['space'] = array(
    '#type' => 'value',
    '#value' => $space,
  );
  $form['feature'] = array(
    '#type' => 'value',
    '#value' => $feature,
  );
  $form['settings'] = array(
    '#tree' => TRUE,
  );
  $form['customizers'] = array(
    '#tree' => TRUE,
  );
  $customizable = FALSE;

  // Generate feature-specific settings form
  $features = spaces_features();
  $f = $features[$feature];
  drupal_set_title(t('Customize: !feature', array(
    '!feature' => $f->spaces['label'],
  )));
  if (isset($f->spaces['settings'])) {
    $form['settings']['#title'] = t('Settings');
    $form['settings']['#type'] = 'fieldset';
    $form['settings']['#collapsible'] = TRUE;
    foreach ($f->spaces['settings'] as $setting) {
      $setting_value = isset($space->settings[$setting->id]) ? $space->settings[$setting->id] : NULL;
      $form['settings'][$setting->id] = $setting
        ->form($space, $setting_value);
    }
    $customizable = TRUE;
  }

  // Create a fieldset per customizer
  $customizers = spaces_customizers();
  foreach ($customizers as $id => $customizer) {
    $form['customizers'][$id] = array(
      '#title' => t($customizer->name),
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#theme' => 'spaces_customize_item',
      '#collapsible' => TRUE,
    );
    $customizer_form = $customizer
      ->form($space, $feature);
    if ($customizer_form) {
      $form['customizers'][$id] = array_merge($form['customizers'][$id], $customizer_form);
      $customizable = TRUE;
    }
  }

  // If we have customizers and/or settings, add submit buttons
  if ($customizable) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save settings'),
      '#submit' => array(
        'spaces_customize_form_submit',
      ),
    );
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
      '#submit' => array(
        'spaces_customize_form_reset',
      ),
    );
  }
  else {
    drupal_set_message(t('This feature does not have any customizations or settings available.'));
  }
  $form['#theme'] = 'spaces_form';
  return $form;
}