You are here

function spaces_preset_default_form in Spaces 6.2

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

Page callback for generating a list of spaces presets. (admin/build/spaces)

1 string reference to 'spaces_preset_default_form'
spaces_menu in ./spaces.module
Implementation of hook_menu().

File

./spaces_admin.inc, line 7

Code

function spaces_preset_default_form(&$form_state) {
  $default_presets = variable_get('spaces_default_presets', array());
  $form = array(
    '#theme' => 'spaces_preset_default_form',
    'types' => array(
      '#tree' => TRUE,
    ),
  );
  foreach (spaces_types() as $type => $info) {
    $form['types'][$type] = array(
      '#tree' => TRUE,
      '#title' => $info['title'],
    );
    $presets = spaces_presets($type, TRUE);
    if (count($presets)) {
      $form['types'][$type]['default'] = array(
        '#type' => 'radios',
        '#options' => array(),
      );
      foreach ($presets as $id => $preset) {

        // Add radio for use when choosing default
        if (!$preset['disabled']) {
          $form['types'][$type]['default']['#options'][$id] = '';
        }

        // Add name for display via theme function
        $form['types'][$type]['name'][$id] = array(
          '#type' => 'markup',
          '#value' => $preset['name'],
        );

        // Set as default if it is
        if ($id == $default_presets[$type]) {
          $form['types'][$type]['default']['#default_value'] = $id;
        }

        // Build links for each preset
        $links = array();
        if (isset($preset['module'])) {
          $links[] = $preset['disabled'] ? l(t('Enable'), 'admin/build/spaces/presets/enable/' . $type . '/' . $id) : l(t('Disable'), 'admin/build/spaces/presets/disable/' . $type . '/' . $id);
        }
        else {
          if (empty($preset['disabled'])) {
            $links[] = l(t('Edit'), 'admin/build/spaces/presets/edit/' . $type . '/' . $id);
            $links[] = l(t('Export'), 'admin/build/spaces/presets/export/' . $type . '/' . $id);
            $links[] = l(t('Disable'), 'admin/build/spaces/presets/disable/' . $type . '/' . $id);
          }
          else {
            $links[] = l(t('Enable'), 'admin/build/spaces/presets/enable/' . $type . '/' . $id);
          }
          switch ($preset['storage']) {
            case SPACES_PRESET_NORMAL:
              $links[] = l(t('Delete'), 'admin/build/spaces/presets/delete/' . $type . '/' . $id);
              break;
            case SPACES_PRESET_OVERRIDDEN:
              $links[] = l(t('Revert'), 'admin/build/spaces/presets/delete/' . $type . '/' . $id);
              break;
          }
        }
        $links = implode(' | ', $links);

        // Store preset information to be passed to theme function
        $form['types'][$type]['info'][$id] = array(
          '#type' => 'value',
          '#value' => array(
            'name' => $preset['name'],
            'description' => $preset['description'],
            'links' => $links,
            'disabled' => $preset['disabled'],
          ),
        );
      }
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save defaults'),
    '#submit' => array(
      'spaces_preset_default_form_submit',
    ),
  );
  return $form;
}