You are here

function collapsiblock_form_alter in Collapsiblock 6

Same name and namespace in other branches
  1. 7 collapsiblock.module \collapsiblock_form_alter()

Implementation of hook_form_alter().

File

./collapsiblock.module, line 110
Make blocks collapsible.

Code

function collapsiblock_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'system_theme_settings') {
    if ($key = $form['#parameters'][2]) {
      $settings = theme_get_settings($key);
      $themes = system_theme_data();
      $features = $themes[$key]->info['features'];
      $settings = array_merge(collapsiblock_default_settings(), $settings, array());
    }
    else {
      $settings = theme_get_settings('');
      $settings = array_merge(collapsiblock_default_settings(), $settings, array());
    }
    collapsiblock_default_settings();

    //$settings = theme_get_settings();
    $form['collapsiblock'] = array(
      '#type' => 'fieldset',
      '#title' => t('Collapsiblock selectors'),
      '#description' => t("Force <a href='http://api.jquery.com/category/selectors/'>CSS selector</a> if collapsiblock doesn't work out of the box"),
      '#weight' => 0,
      '#attributes' => array(
        'id' => 'collapsiblock_form',
      ),
    );
    $form['collapsiblock']['collapsiblock_block'] = array(
      '#type' => 'textfield',
      '#title' => t('Block'),
      '#default_value' => $settings['collapsiblock_block'],
    );
    $form['collapsiblock']['collapsiblock_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#default_value' => $settings['collapsiblock_title'],
    );
    $form['collapsiblock']['collapsiblock_content'] = array(
      '#type' => 'textfield',
      '#title' => t('Block content'),
      '#default_value' => $settings['collapsiblock_content'],
    );
  }
  if ($form_id == 'block_admin_configure') {
    $settings = variable_get('collapsiblock_settings', array());
    $form['#submit'][] = 'collapsiblock_submit';
    $form['collapsiblock'] = array(
      '#type' => 'fieldset',
      '#title' => t('Collapsible'),
      '#collapsible' => TRUE,
      '#weight' => -5,
    );
    $form['collapsiblock']['collapse_type'] = array(
      '#type' => 'radios',
      '#title' => t('Block collapse behavior'),
      '#options' => array(
        1 => t('None.'),
        2 => t('Collapsible, expanded by default.'),
        3 => t('Collapsible, collapsed by default.'),
        4 => t('Collapsible, collapsed all the time.'),
      ),
      '#default_value' => $settings['block-' . $form['module']['#value'] . '-' . $form['delta']['#value']] ? $settings['block-' . $form['module']['#value'] . '-' . $form['delta']['#value']] : variable_get('collapsiblock_default_state', 1),
    );
  }
}