'admin/settings/collapsiblock', 'title' => t('Collapsiblock'), 'description' => t('Configuration for collapsible blocks'), 'callback' => 'drupal_get_form', 'callback arguments' => array('collapsiblock_admin_settings') ); } else { collapsiblock_load(); } return $items; } /** * Admin settings. */ function collapsiblock_admin_settings() { $form = array(); $form['collapsiblock_default_state'] = array( '#type' => 'radios', '#title' => t('Default block collapse behavior'), '#options' => array(1 => t('None.'), 2 => t('Collapsible, expanded by default.'), 3 => t('Collapsible, collapsed by default.')), '#default_value' => variable_get('collapsiblock_default_state', 1), ); $form = system_settings_form($form); return $form; } /** * Load needed files. */ function collapsiblock_load() { static $loaded = FALSE; if (!$loaded) { $path = drupal_get_path('module', 'collapsiblock'); jstools_add_js($path . '/collapsiblock.js'); drupal_add_js(drupal_get_path('module', 'jstools') .'/jquery.cookie.js'); drupal_add_js(array('collapsiblock' => array('blocks' => variable_get('collapsiblock_settings', array()), 'default_state' => variable_get('collapsiblock_default_state', 1))), 'setting'); drupal_add_css($path .'/collapsiblock.css'); $loaded = TRUE; } } function collapsiblock_form_alter($form_id, &$form) { if ($form_id == 'block_admin_configure') { $settings = variable_get('collapsiblock_settings', array()); $form['#submit']['collapsiblock_submit'] = array(); $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.')), '#default_value' => $settings['block-' . $form['module']['#value'] . '-' . $form['delta']['#value']] ? $settings['block-' . $form['module']['#value'] . '-' . $form['delta']['#value']] : variable_get('collapsiblock_default_state', 1), ); } } function collapsiblock_footer() { drupal_add_js(array('collapsiblock' => jstools_theme_data('collapsiblock')), 'setting'); } function collapsiblock_submit($form_id, $edit) { $settings = variable_get('collapsiblock_settings', array()); $settings['block-' . $edit['module'] . '-' . $edit['delta']] = $edit['collapse_type']; variable_set('collapsiblock_settings', $settings); }