You are here

function admin_settings_form in Admin 6.2

Same name and namespace in other branches
  1. 7.2 admin.admin.inc \admin_settings_form()

System settings form for admin toolbar.

1 string reference to 'admin_settings_form'
admin_menu_alter in ./admin.module
Implementation of hook_menu_alter().

File

./admin.admin.inc, line 6

Code

function admin_settings_form() {
  $form['admin_toolbar'] = array(
    '#tree' => TRUE,
    '#theme' => 'admin_settings_form',
  );
  $form['admin_toolbar']['layout'] = array(
    '#type' => 'select',
    '#title' => t('Layout'),
    '#description' => t('Choose a layout for the admin toolbar. Vertical works well with large, wide screens. Horizontal works well on screens with limited real estate.'),
    '#options' => array(
      'horizontal' => t('Horizontal'),
      'vertical' => t('Vertical'),
    ),
    '#default_value' => admin_get_settings('layout'),
  );
  $form['admin_toolbar']['position'] = array(
    '#type' => 'select',
    '#title' => t('Position'),
    '#description' => t('Choose a position for the admin toolbar that will not collide with other elements in your current theme.'),
    '#options' => array(
      'ne' => t('Top right'),
      'nw' => t('Top left'),
      'se' => t('Bottom right'),
      'sw' => t('Bottom left'),
    ),
    '#default_value' => admin_get_settings('position'),
  );
  $form['admin_toolbar']['behavior'] = array(
    '#type' => 'select',
    '#title' => t('State on new pages'),
    '#description' => t('Choose toolbar behavior on new page loads.'),
    '#options' => array(
      'df' => t('Remember from previous page'),
      'ah' => t('Collapsed'),
    ),
    '#default_value' => admin_get_settings('behavior'),
  );
  $block_info = array();
  foreach (module_implements('block') as $module) {
    $module_blocks = module_invoke($module, 'block', 'list');
    if ($module_blocks) {
      foreach ($module_blocks as $delta => $info) {
        $block_info["{$module}-{$delta}"] = $info;
      }
    }
  }

  // Store block info for use in form processing.
  $form['#block_info'] = $block_info;

  // Get default block options.
  $options = array();
  $enabled = array_filter(admin_get_settings('blocks')) + admin_get_default_blocks(TRUE);
  foreach ($block_info as $bid => $info) {
    if (!empty($enabled[$bid])) {
      $options[$bid] = $info['info'];
    }
  }
  asort($options);
  $form['admin_toolbar']['blocks'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => drupal_map_assoc(array_keys(array_filter(admin_get_settings('blocks')))),
  );

  // Grab an array of human-readable module names. It hurts that we need to do this.
  $result = db_query("SELECT name,type,info FROM {system} WHERE type = 'module' AND status = 1");
  $modules = array();
  while ($row = db_fetch_object($result)) {
    $info = unserialize($row->info);
    $modules[$row->name] = isset($info['name']) ? $info['name'] : $row->name;
  }
  foreach (array_diff_key($block_info, $options) as $bid => $info) {
    $module = array_shift(explode('-', $bid));
    $module = isset($modules[$module]) ? $modules[$module] : $module;
    $custom_options[$module][$bid] = $info['info'];
  }
  $custom_options = $custom_options + array(
    -1 => '<' . t('Choose a block') . '>',
  );
  ksort($custom_options);
  $form['admin_toolbar']['custom'] = array(
    '#type' => 'select',
    '#options' => $custom_options,
    '#default_value' => -1,
    '#element_validate' => array(
      'admin_settings_form_custom_validate',
    ),
    '#description' => t('Enable other blocks for use in the admin toolbar.'),
  );
  $form['admin_toolbar']['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add block'),
  );
  $form = system_settings_form($form);

  // Add a submit handler for expanding block information.
  array_unshift($form['#submit'], 'admin_settings_form_submit');
  return $form;
}